symfonyのフォームに追加フィールドにデフォルト値を設定する方法
-
19-09-2019 - |
質問
私が行うために必要なものは、「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。:ところで...私はPropelとsymfonyの1.4を使用する
解決
あなたはsfWidgetFormInputPassword
ウィジェットを使用しているので、あなたのデフォルトが機能していない理由はあります。
ベスト・プラクティスは、パスワードフィールドを事前に埋めることはありませんすることであり、これはsfWidgetFormInputPassword
ウィジェットがあなたのために何をするかです。
あなたがベストプラクティスに反するしたい場合は、以下の操作を行い、
$this->widgetSchema['passwordagain']->setOption('always_render_empty', false);
しかし、私は真剣にあなたがそれをしないお勧めします。
所属していません StackOverflow