0

I am facing trouble to remove value from password field. When I submit signup form without entering one or more required field then its generate a 32 bit character value on password field.

I want to see this field blank in that case.

With Thanks,

MRS

1
  • 1
    please post the validation and authentication code you are using
    – dInGd0nG
    Sep 11, 2012 at 14:07

3 Answers 3

0

It's hard to say without some code, but it sounds like when the form validation fails on signup the form is re-populated (since it's CActiveForm) with the data from the signup submission - which now includes the password which you have hashed?

One way to avoid this would be, on form submit, to just clear out the password after the save() or validate() fails. I'm guessing if you have basic Yii code your form post action will look something like this:

$model->attributes = $_POST['SignupModel'];
$model->password = cool_hash_function($model->password); // hashing the password - maybe you have this in beforeValidate(), I don't know
if ($model->save()) {
  $this->redirect('/success!'); // yay! redirect or whatever
} else {
  $model->password = ''; // if the save failed, clear out the password before re-rendering the form
}
$this->render('signup',array('model'=>$model)); // the form will now render without the pw

Yes, the user will need to re-enter their password. There might be other approaches to this depending on where in the process you are hashing the password before saving - and depending if I have come close to guess your actual issue. :)

0
0

You can do it also in the code of view file, using the $htmlOptions parameter of CActiveForm / CHtml methods, and force the password input to render an empty value attribute:

<?= CHtml::activePasswordField($model, 'password', array('value'=>'')) ?>
<?= $form->passwordField($model, 'password', array('value'=>'')) ?>
0

Your code is really bad, because you are getting into Model functionality from the Controller, which violates rules of the MVC Programming Pattern.

Instead this code should be put in the User's model class within the beforeSave() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.