I try to build a user management system. for that i need a form to create a new user. it’s working fine untill i build in a second password field “ConfirmPassword”.
on submit i get the error: Property "User.PasswordConfirm" is not defined.
i think yii is giving me the error because the field doesn’t exist in the database.
how can i get this working?
below the code:
public function rules()
array('GroupId, FirstName, LastName, Email, Username, Password, PasswordConfirm', 'required'),
array('Password', 'compare', 'compareAttribute' => 'PasswordConfirm')
public function safeAttributes()
return array('GroupId', 'FirstName', 'LastName', 'Email', 'Username', 'Password', 'PasswordConfirm');
Piece of the form
<?php echo CHtml::Label('Nogmaals', 'User_PasswordConfirm'); ?>
<?php echo CHtml::activePasswordField($user, 'PasswordConfirm', array('value' => '')); ?>
just add a public var to extend your model with this field:
damnit, thats it! thanks yoshi
is it a good idea to declare you fieldname in the model everytime?
another question: all the field exept the Email field doesn’t get the class=“error” attribute if the validation failed.
is this a bug?
Yes, you need to add these variables. Otherwise the model couln’t ‘know’ these fields, because they don’t belong to the db table.
Have you tried
array('Email', 'email', 'allowEmpty'=>false),
Hi! And … what we have to do if the field is a checkbox and we want that users check it!?
You can use it in the rules as required if they need to check it, another way is to use the parameter checked on your checkbox, this way it’s auto checked and users have to select or deselect it.
<?php echo $form->checkBox($model,'name', array('checked'=>'checked')); ?>
I followed this code, but the password and confirm password both are also required in updated case, what is the solution of this problem.
Please help me.