Password repeat field


I want to create a user creation form, based on a CActiveForm with a CActiveRecord Model.

In this form i would like a password repeat field, wich should only exist to compare the 2 password fields. How can i do since, if in understand, i cannot use a field that does not exist in the database ?


Your field to comparison dont need exist in database, just in your model.

Something like:

class MyModel


	public $pwd_comparison;


	public function rules()



    	//'safe' allow you do myModel->attributes=$_POST['myModel'] to get your pwd_comparison setted.  

    	//The on=>create is optional.

    	array('pwd_comparison', 'safe', 'on'=>'create'); 


Thank you !

You are welcome.

From the Compare validator API:

My model looks like this:


class User extends CActiveRecord


	//container for repeated password on create user form

	public $password_repeat;

public function rules()


	return array(

		array('password', 'compare'),

		array('password_repeat', 'safe'),

Why you declare the field as public and not private with a get method?

It’s for quick testing the idea, you can declare it as private / protected and use get/set method to turn it into a property. When you have property, rules work.

You could write getters / setters but why?

I am not going to inherit from this class and restrict access to it. I am not an OOP expert but in this case I see no need to make it private. Please let me know if I am missing something.