Validates field "Input current password" in your model.
Yii 1.1 or above
class User extends CActiveRecord { public $old_password; public $new_password; // ... public function rules() { return array( // ... // Settings scenario array('old_password', 'required', 'on' => 'settings'), array('old_password', 'DCurrentPassword', 'on' => 'settings'), )); } public function validatePassword($password) { return $this->hashPassword($password) === $this->password; } }
Or:
public function rules() { return array( // ... array('old_password, new_email, new_password, new_confirm', 'length', 'max'=>255), array('new_email', 'email'), array('new_password', 'length', 'min'=>6, 'allowEmpty'=>true), array('new_confirm', 'compare', 'compareAttribute'=>'new_password'), array('old_password', 'DCurrentPassword', 'on'=>'settings', 'dependsOnAttributes'=>array('new_password', 'new_email'), 'emptyMessage'=>'Current password required for change email or password', 'notValidMessage'=>'Current password is not correct', ), )); }
More examples see there:
Be the first person to leave a comment
Please login to leave your comment.