Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeat Password does not work in Yii2

Tags:

php

yii

yii2

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.

like image 300
StreetCoder Avatar asked Mar 11 '15 06:03

StreetCoder


1 Answers

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" ],
    ];
like image 160
arkoak Avatar answered Nov 07 '22 13:11

arkoak