0

我需要做的是通过添加“再次密码”字段来自定义我的默认用户表单,并将值设置为等于“密码”字段的新字段。我的代码:

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'));

} }

那里的 setDefault 方法似乎不起作用。也许它只适用于新用户,但这不是我在这里寻找的。

谢谢,拉杜。

PS:顺便说一句...我使用带推进器的 symfony 1.4

4

1 回答 1

2

您的默认设置不起作用的原因是您正在使用sfWidgetFormInputPassword小部件。

最佳做法是永远不要预先填写密码字段,这就是sfWidgetFormInputPassword小部件为您所做的。

如果您想违背最佳实践,请执行以下操作,

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

但是,我强烈建议您不要这样做。

于 2010-02-07T21:19:40.713 回答