我的 Kohana 视图文件如下所示:
<?=Form::open('/signup/user');?>
<?=Form::label('username', 'Username: ')?>
<?=Form::input('username', isset($username)?$username:''); ?>
<br />
<?=Form::label('password', 'Password: ')?>
<?=Form::password('password', ''); ?>
<br />
<?=Form::label('confirm', 'Re-enter Password: ')?>
<?=Form::password('confirm', ''); ?>
<br />
<?=Form::label('email', 'Email: ')?>
<?=Form::input('email', ''); ?>
<?=Form::submit('submit', "Submit"); ?>
<?=Form::close()?>
我的控制器:
public function action_user(){
if($this->request->method() == "POST"){
$this->template->set('username', $this->request->post('username'));
$user = ORM::factory('user');
try{
$user->values($_POST)->save();
}catch(ORM_Validation_Exception $e){
var_dump($e->errors());
}
}
}
问题是后者会接受密码为空或密码不匹配的表单并将其写入数据库。用户名和电子邮件字段验证工作正常,但我不确定如何验证密码字段。