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 回答