0
我需要做的是通過添加'passwordagain'字段並將該值設置爲等於'password'字段的新字段來自定義我的默認userForm。 我的代碼:如何將默認值設置爲symfony表單中的額外字段
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推進
你說得對。當我想到更多關於它的時候,db中的密碼是md5,所以如果我使用那個值來渲染字段,它不會做任何好事。 感謝您的幫助。 – 2010-02-08 06:37:22