validation to compare password

I seem to have a tiny hickup here.

I have these rules:





			array('password', 'length', 'min'=>6, 'max'=>64, 'on'=>'register, recover'),

			array('password_repeat', 'required', 'on'=>'register, recover'),

			array('password', 'compare', 'compareAttribute'=>'password_repeat' , 'on'=>'register, recover'),



(I realize I don’t need to specify compareAttribute here)

On the form it shows the pw field, then the verity pw field. Right after I type in the password, it gives the error about it needing to repeat exactly on the pw field rather than the pw verify field. It’s no problem if I simply change the compare rule to this:


array('password_repeat', 'compare', 'compareAttribute'=>'password' , 'on'=>'register, recover'),

But all the examples I’ve seen don’t have it needing to be done that way. What am I doing backwards?

you have found the solution…nothing backwards

So I should have this:


array('password_repeat', 'compare', 'compareAttribute'=>'password' , 'on'=>'register, recover'),



[font="monospace"][size="2"]?[/size][/font]

[font="monospace"] [/font]

[font="monospace"][size="2"]I was looking at the yii-user-management code, and it has the compare on the password, but the error shows up on the verify password.[/size][/font]

You can use something like this:




array('password', 'length', 'min'=>6, 'max'=>64, 'on'=>'register, recover'),

array('password', 'compare','on'=>'register, recover'),

array('password_repeat', 'safe'),

password_repeat is default value for comparing, so you don’t have to enter it.

Also you don’t have to require password_repeat field, if it is empty, it will not match with password, which is required field anyway.

And I made password_repeat safe, so you can use mass assignment in your actions.

Right, but usually the password_repeat box is after the main password box. It doesn’t make sense to give an error about it not matching until they at least have the opportunity to type it a second time. But the way you have it, it compares the password to password_repeat before password_repeat has been typed in and always give the error. The error appears on the password field, not the password_repeat field.

So shouldn’t it be backwards?


array('password_repeat', 'compare', 'compareAttribute'=>'password' ,'on'=>'register, recover'),