我有一个配置文件页面,当用户尝试更新他们的页面配置文件并且输入未根据验证规则进行验证时,它仍然继续保存(或至少输出成功消息),但没有任何数据被存储,它恢复到原始值。只有当验证规则通过时,它才会存储值。
我不确定如何解决这个问题,因为我的验证规则看起来是正确的。有任何想法吗?
验证规则
public $validate = array(
"username" => array(
"email" => array(
"rule" => "email",
"message" => "The username must be a valid email address."
),
"unique" => array(
"rule" => "isUnique",
"message" => "This username has already been registered."
)
),
"password" => array(
"alphaNumeric" => array(
"rule" => "alphaNumeric",
"message" => "The password can only contain alpha-numeric characters"
),
"between" => array(
"rule" => array("between",8,12),
"message" => "The password must contain between 8 - 12 characters."
)
),
"company" => array(
"rule" => "notEmpty",
"message" => "Please provide a company name"
),
"first_name" => array(
"rule" => "notEmpty",
"message" => "Please provide the contact person's first name"
),
"last_name" => array(
"rule" => "notEmpty",
"message" => "Please provide the contact person's last name"
),
"telephone" => array(
"numeric" => array(
"rule" => "numeric",
"message" => "The telephone number must be numeric"
),
"maxLength" => array(
"rule" => array("maxLength",10),
"message" => "Your telephone umber must be 10 numbers."
)
),
"fax" => array(
"numeric" => array(
"rule" => "numeric",
"message" => "The fax number must be numeric"
),
"maxLength" => array(
"rule" => array("maxLength",10),
"message" => "Your fax umber must be 10 numbers."
)
),
"user_type_id" => array(
"rule" => "numeric",
"message" => "Please select a user type"
),
"user_status_id" => array(
"rule" => "numeric",
"message" => "Please select the users status."
)
);
控制器方法:
public function profile() {
if($this->request->is('post') || $this->request->is('put')) {
if($this->Auth->user("id") == $this->request->data['User']['id']) {
$this->User->save($this->request->data);
$this->Session->setFlash('Your profile has been updated','default',array('class'=>'success'));
} else {
$this->Session->setFlash("An error has occured updating your profile.");
}
}
$this->request->data = $this->User->read(null,$this->Auth->user("id"));
}