How To Override A Variable In A Form And Submit

[font=“Times New Roman”]I’m working on a password reset form that has the following fields


<==Username==>


<==Current Password==>


<==New Password==>


<==Confirm Password==>

  [b]View code[/b]



      <div class="row"><?php 

        echo $form->labelEx($model,'username'); 

        echo $form->textField($model,'username',array('size'=>45,'maxlength'=>150)); 

        echo $form->error($model,'username'); ?>

      </div>    

       

      <div class="row"><?php         

        echo $form->labelEx($model,'Current password');

        $model->password="";

        echo $form->textField($model,'password',array('size'=>45,'maxlength'=>150)); 

        echo $form->error($model,'password'); ?>

      </div>

    

      <div class="row"><?php   

        echo $form->labelEx($model,'New password');

        $model->password="";

        echo $form->passwordField($model,'password',array('size'=>45,'maxlength'=>150)); 

        echo $form->error($model,'password'); ?>

      </div>


       <div class="row">  

       <?php echo $form->label($model,'password_repeat'); ?>    

       <?php echo $form->passwordField($model,'password_repeat',array('size'=>45,'maxlength'=>150)); ?>    

       <?php echo $form->error($model,'password_repeat'); ?> 

       </div>


       <div class="row buttons"><?php 

        echo CHtml::submitButton('Reset Your Password');

        ?></div><?php



   [b]Controller code[/b]



       	public function actionUpdate($id)

	{

		$model = $this->loadModel($id);

    

    // set the parameters for the bizRule

    $params = array('GroupzSupport'=>$model);

    // now check the bizrule for this user

    if (!Yii::app()->user->checkAccess('updateSelf', $params) &&

        !Yii::app()->user->checkAccess('admin'))

    {

        throw new CHttpException(403, 'You are not authorized to perform this action');

    }

      else

    {

          

       if(isset($_POST['GroupzSupport']))

		{                        

			$model->attributes=$_POST['GroupzSupport'];

                        $model->password = $model->hashPassword($_POST['GroupzSupport']['password']);

			if($model->save())

				$this->redirect(array('admin','id'=>$model->id));

		}


		$this->render('update',array(

			'model'=>$model,

		));

    }

	}




       

   Now, I need to override the current password to new password. How can I do this.

[/font]

You render two fields for the same attribute. You can’t do that, because they will have the same ‘name’ attribute and value of one will be overwritten with the second one in POST data.

Just add virtual attributes as properties of your model class and then process them manually in the action. First check current password, then validate if new password matches the confirmation and then hash it and put into the password field.