什么我需要做的是通过添加“passwordagain”字段定制我的默认用户窗体和值设置为新字段等于“密码”字段。 我的代码:

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方法存在似乎不工作。也许这仅适用于新用户,但是这不是我期待在这里。

谢谢, 拉杜。

P.S .:顺便说一句...我使用的symfony 1.4与推进

有帮助吗?

解决方案

默认是不工作的原因是因为你使用的sfWidgetFormInputPassword部件。

最佳做法是永远不会预先填充密码字段,这是sfWidgetFormInputPassword小部件做什么你。

如果你想违背最佳实践,做到以下几点,

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

不过,我认真建议你不这样做。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top