I have written rules in the model as:
public $password_repeat;
/**
* @inheritdoc
*/
public function rules()
{
return [
....
....
['password', 'required'],
['password', 'string', 'min' => 6],
['password_repeat', 'compare', 'compareAttribute'=>'password', 'message'=>"Passwords don't match" ],
];
}
If I use different password in Password
and Password Repeat
field, it gives error. So, that's mean it works. But problem is that, it does not give any error if Password Repeat
field is empty.
Add a required tag for password_repeat as well. Shown below
return [
....
['password', 'required'],
['password', 'string', 'min' => 6],
['password_repeat', 'required'],
['password_repeat', 'compare', 'compareAttribute'=>'password', 'message'=>"Passwords don't match" ],
];