ログインフォームを検証するために、cakephpの検証を長い間チェックしてきました。私の問題は、ユーザー名とパスワードを空白として入力すると、検証が表示されないことです。
UserController.phpのログイン関数には
if ($this->request->is('post')) {
$this->user->set($this->request->data);
$errors = $this->user->invalidFields();
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash($this->Auth->authError, 'default', array(), 'auth');
$this->redirect($this->Auth->loginAction);
}
} else {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
}
私のUser.phpモデルにはバリデーターが含まれています
public $validate = array(
'username' => array(
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'The username has already been taken.',
),
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.',
),
),
'email' => array(
'email' => array(
'rule' => 'email',
'message' => 'Please provide a valid email address.',
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'Email address already in use.',
),
),
'password' => array(
'rule' => array('minLength', 6),
'message' => 'Passwords must be at least 6 characters long.',
),
'current_password' => array(
'rule' => '_identical',
),
'name' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.',
),
);
実際、私のログインフォームにはusgernameとパスワードしか含まれていません。しかし、私はユーザー登録フォームにこの検証を設定しました。検証は登録フォームで正しく機能しましたが、ログインの場合、検証は機能しませんでした。はい、同じ問題に関してこのWebサイト自体に多くの質問が投稿されていることを知っていますが、私の問題を解決するものは何もありません。私はすべてのstackoverflowの質問を試しました。助けてください