0

データベースにない場合に new_password フィールドと confirm_password フィールドを一致させる方法は?

こんにちは...フィールド「new_password」と「confirm_password」を一致させる方法を知りたいです。これらはデータベースに保存されず、パスワード変更モジュールで一致する目的で使用されます。

私はこれを試しましたが、うまくいきませんでした:

if($this->data['User']['new_password'] != $this->data['User']['confirm_password'] ) {
  $this->Session->setFlash("New password and Confirm password field do not match");
} else {
  $this->data['User']['password'] = $this->data['User']['new_password'];
  $this->data['User']['id'] = $this->User->id;

  if($this->User->save($this->data)) {
    $this->Session->setFlash("Password updated");
    $this->redirect('/users/login');
  }
}
4

1 に答える 1

0

これを試すことができます:

// check for empty value

if( !empty( $this->data['User']['new_password'] ) && !empty( $this->data['User']['confirm_password'] ) ) {

   if( $this->data['User']['new_password'] != $this->data['User']['confirm_password']) {

       $this->Session->setFlash("New password and Confirm password field do not match");

   } else {

       $this->data['User']['password'] = $this->data['User']['new_password'];
       $this->data['User']['id'] = $this->User->id;

       if( $this->User->save($this->data) ) {

          $this->Session->setFlash("Password updated");
          $this->redirect('/users/login');

       } else {

          $this->Session->setFlash('Password update fail');

       }
   }

} else {

   $this->Session->setFlash('Enter New password and Confirm password');

}
于 2012-07-14T16:46:42.077 に答える