|
PHP复制代码 <?php defined('SYSPATH') OR die('No direct access allowed.');
/**
\\kohana\\application\\controllers\\register.php
*/
class Register_Controller extends Controller
{
function index ()
{
$view = new View ('view');
$view->form = array
(
'email' => '',
'type' => '',
);
$view->errors = $view->form;
$view->title = "KOHANA 表单验证功能测试";
$view->selection = array('basic' =>'市级管理员', 'standard' => '区级管理员', 'custom' => '街道管理员');
$post = new Validation ($_POST);
$post->add_rules('email', 'required', 'email');
if ($post->validate())
{
die(html ::anchor('login/index', '注册成功了!'));
}
else
{
// 重新载入表单字段
$view->form = arr :verwrite ($view->form, $post->as_array());
// 传递错误字段,并且我们需要创建一个错误信息文件
// Kohana 通过 errors() 方法调用错误信息文件传递错误信息
// 需要自定义 application/i18n/en_US/form_errors.php
$view->errors = arr :verwrite ($view->errors, $post->errors('form_errors'));
}
$view->render(TRUE);
}
} 复制代码 |
|