Hi , i have problem with validation but cant understand what the problem is ,
i have problem in password change file ,
i use following code in view file , here PASSWORD AND CPASSWORD are not db field ( in db i want update field name e_password )
<div class="row">
<?php echo $form->labelEx($model,'PASSWORD'); ?>
<?php echo $form->passwordField($model,'PASSWORD'); ?>
<?php echo $form->error($model,'PASSWORD'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'CPASSWORD'); ?>
<?php echo $form->passwordField($model,'CPASSWORD'); ?>
<?php echo $form->error($model,'CPASSWORD'); ?>
</div>
as these are extra fields i use following things in model file ,
public $PASSWORD; // declare fields in class of model
public $CPASSWORD;
array('E_NAME, .... , PASSWORD , CPASSWORD', 'required'),
array('PASSWORD', 'compare', 'compareAttribute'=>'CPASSWORD' ,'message'=>'Password and Confirm Password do not match'), // for password compare
now i use following code in action controller file ,
...
...
if(isset($_POST['Employee']))
{
$newPass = $_POST['Employee']['PASSWORD'];
$model->attributes=$_POST['Employee'];
if($model->validate())
{
if($model->changePass($id,$newPass)) // function for update password
{
Yii::app()->user->setFlash('success',"Your account updated successfully.");
$this->redirect(array('account'));
}
}
$this->render('account',array(
'model'=>$model,
'empData'=>$empData,
));
}
=> now the problem is when i use if($model->validate()) it validates but data not store in database , i.e condition is not satisfied .
– when i remove if($model->validate()) , the data saved but error not shown …
=> and another big problem is when i use this fields ( PASSWORD AND CPASSWORD ) WHICH ARE NOT IN DB , the other pages stop working like create employee … ( might be problem due to extra field ) …