views:

427

answers:

1

What i need to do is customize my default userForm by adding a 'passwordagain' field and set the value to the new field equal to the 'password' field. My code:

class UserForm extends BaseUserForm
{
 public function configure()
 {

$this->widgetSchema['password'] = new sfWidgetFormInputPassword();
$this->widgetSchema['passwordagain'] = new sfWidgetFormInputPassword();

$this->validatorSchema['password'] = new sfValidatorString();
$this->validatorSchema['passwordagain'] = new sfValidatorString();

$this->getValidatorSchema()->setPostValidator(
  new sfValidatorSchemaCompare(
    'password',
    sfValidatorSchemaCompare::EQUAL,
    'passwordagain',
    array(),
    array('invalid' => 'Passwords don\'t match')
));

$this->setDefault('passwordagain', $this->getObject()->getPassword());

$this->useFields(array('username', 'password', 'passwordagain'));

} }

The setDefault method there doesn't seem to work. Perhaps it works only for new users, but that's not what i am looking for here.

Thanks, Radu.

P.S.: btw... i use symfony 1.4 with propel

A: 

The reason your default isn't working is because you're using the sfWidgetFormInputPassword widget.

Best practice is to never pre-fill a password field, and this is what the sfWidgetFormInputPassword widget does for you.

If you want to go against best practice, do the following,

$this->widgetSchema['passwordagain']->setOption('always_render_empty', false);

However, I seriously recommend you don't do that.

Stephen Melrose
You are right. When i think more about it, the password in db is md5, so it wont do any good if i render the field with that value. Thanks for the help.
Radu Dragomir