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