In the user registration form, I have password and password2 so that user has to enter password 2x and they have to equal each other before he/she is registered. The validation rules work fine in this case. In the update user info form. I have both password and password2 set to blank so that if the user does not enter a value in the first password field or password2 field, then the system simply saves the current password which I have stored in a temporary variable in my user model. So far so good. What I want is to trigger all the same validation rules as when registering but ONLY if the user enters a value in the first password field, but leave blank and ignore otherwise. So I guess this is some kind of conditional validation.
In the user model:
$validate = array(
'password' => array(
'password_notempty'=>array(
'rule' => 'notEmpty',
'message' => 'Required field',
'on' => 'create')
,
'password_between'=>array(
'rule' => array('between', 5, 15),
'message' => 'Between 5 to 15 characters',
'on' => 'create')
,
'password_alphanumeric'=>array(
'rule' => 'alphaNumeric',
'message' => 'Characters and numbers only',
'on' => 'create')
),
'password2' => array(
'password2_isequal' =>array(
'rule' => array('comparePasswords','password'),
'message' => 'Must be same value as password.')
)
);
Anyone have ideas on how to accomplish this?