Hi All,
I think I’m missing something really obvious here, so if someone could point me in the right direction I’d really appreciate it!
Basically, all I’m trying to do is have a ‘confirm password’ option on my sites registration form.
I have a user class, which has the following within it:
public $password_repeat; // as it's not a database field
...
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
...
array('password', 'compare', 'on'=>'registration', 'compareAttribute'=>'password_repeat'),
);
}
...
Within my view file, it’s simply called within a CActiveForm call like:
...
<tr>
<td></td>
<td align="left">
<h4><?php echo $form->labelEx($model,'password'); ?></h4>
<label>
<?php echo $form->passwordField($model,'password',array('size'=>15,'maxlength'=>15,'value'=>'')); ?>
<?php echo $form->error($model,'password'); ?>
</label></td>
</tr>
<tr>
<td></td>
<td align="left">
<h4><?php echo $form->labelEx($model,'password_repeat'); ?></h4>
<label>
<?php echo $form->passwordField($model,'password_repeat',array('size'=>15,'maxlength'=>15,'value'=>'')); ?>
<?php echo $form->error($model,'password_repeat'); ?>
</label></td>
</tr>
...
And finally, I try to validate the form in the controller:
$formuser = new User;
$formuser->setRegistration();
if(isset($_POST['User']))
{
$formuser->attributes=$_POST['User'];
if($formuser->validate())
...
This works fine for everything else, I print_r($formuser) and it’s set all the other registration values, but not password_repeat, so $formuser->validate() returns null (as it looks like ‘password_repeat’ is null, so therefore not the same as ‘password’), and the registration fails giving the error:
Please fix the following input errors:
Password must be repeated exactly.
So the questions is, what have I missed? lol
Thanks!
Stu