ユーザーがページプロファイルを更新しようとしたときに、入力が検証ルールに従って検証されないプロファイルページがありますが、保存は続行されます (または少なくとも成功メッセージが出力されます) が、データは保存されません、元の値に戻ります。検証ルールが渡された場合にのみ、値が保存されます。
検証ルールが正しいように見えるため、これを修正する方法がわかりません。何か案は?
検証規則
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"));
}