我的用户模型:
class User extends AppModel {
public $validate = array(
'username' => 'alphaNumeric',
'password' => 'notempty',
'confirmpassword' => 'notempty',
'group_id' => 'notempty',
'email' => array(
'rule' => 'email',
'message' => 'Please provide a valid email address.'
),
);
}
我的用户注册视图:
<div class="users form">
<?php echo $this->Form->create('User'); ?>
<fieldset>
<legend><?php echo __('Register User'); ?></legend>
<?php
echo $this->Form->input('User.username');
echo $this->Form->input('User.password');
echo $this->Form->input('User.confirmpassword', array('type'=>'password', 'label'=>'Confirm password'));
echo $this->Form->input('User.group_id');
echo $this->Form->input('User.email');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
我在控制器中的用户注册操作:
public function register() {
if ($this->request->is('post')) {
...
//create mail for verification
$email = new CakeEmail();
...
$email->to($this->data['User']['email']);
$email->send($ms);
}
}
访问 /users/register,当我在电子邮件字段中输入“asdfgh”之类的内容时,我收到默认的 CakePHP 错误消息:
Invalid email: asdfgh
Error: An Internal Error Has Occurred.
而不是电子邮件字段上方的错误消息,告诉我:
Please provide a valid email address.
我的问题:当用户的输入数据无效时,它真的应该调用控制器中的动作吗?只有当用户的输入数据有效时,有没有办法在控制器中调用操作?