Add display/processing use only new field to a CRUD create page?

Let’s say i have a user table with fields name, email, password.

I generated CRUD pages with gii.

So the create page will show

name:

email:

password:

Now i need to have something like

name:

email:

confirm email:

password:

confirm password:

What is the best way to do that?

Did you add the both [color="#FF0000"]confirm email:[/color] and [color="#FF0000"]confirm password:[/color] in to table.

Then you have to add the model and view files related to this table.It’s better if you can delete those files and folders and created the crud again.But you won’t do that let me know…I’ll tell where to edit… :P

Nope my table do not have that 2 field and it shouldn’t have that :P

Any other way to do this besides adding confirm email and confirm password to my user table? The 2 field shouldn’t be store in the table.

just declare the two fields in your model so you can use them and validate them. but you will have to change your view file as well if you wish to use them. The easiest way is to use some of the ready-made user extensions

I have a look on yii user extension and i think it is complicated and will become a black box for me. I would like to build my yii app from ground up and step by step. This way i will understand my yii app 100%.

In my models/user.php i can’t figure out where i should add the two field. I tried adding to attributeLabels() but the field would not show.

And then i have a look at views/user/create.php and it has one line

<?php echo $this->renderPartial(’_form’, array(‘model’=>$model)); ?>

which totally confuse me as i don’t know how renderPartial got the fields it needs to display from.

I then tried add the field to views/user/_form with

&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'RetypePassword'); ?&gt;


	&lt;?php echo &#036;form-&gt;passwordField(&#036;model,'RetypePassword'); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'RetypePassword'); ?&gt;


&lt;/div&gt;

I got an exception of Property “User.RetypePassword” is not defined. I am stucked :(

Hi,

seems that you haven’t read Yii’s guide, which covers form processing very well.

In your particular case first you need to add new public attributes to the model, then add validation rules for them, and after that add code to the view file (this will eliminate an exception of Property "User.RetypePassword" is not defined). The model should look like:





class YourModel extends CActiveRecord

{

	//add these decarations

	public $password_repeat;

	public $email_repeat;

	

	...


	public function rules()

	{

		return array(

			array('username, password', 'required'),

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

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

			array('email_repeat', 'required', 'on'=>'register'),

			array('email', 'compare', 'on'=>'register'),

		);

	}


...


}



To better understand what is going on please also read documentation for CCompareValidator.

I got it! MaxAnd :)

Thank you all for the advices.