Formbuilder RepeatedType PasswordType 占位符
Formbuilder RepeatedType PasswordType placeholder
我使用 Symfony 表单生成器制作重复类型 (RepeatedType) 的密码字段 (PasswordType):
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'required' => true,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
'constraints' => [
new Assert\NotBlank(['message' => "Ce champ est obligatoire."]),
new Assert\Length([
'min' => 8,
'minMessage' => 'Le mot de passe doit comporter plus de {{ limit }} caractères.',
]),
],
'invalid_message' => 'Le mot de passe doit être identique.',
'options' => ['attr' => [
'class' => 'password-field',
'placeholder' => "Mot de passe"
]],
])
但是我想为 2 个密码输入设置 2 个不同的占位符,我不知道该怎么做。
您可以将 attr
属性添加到 first_options
和 second_options
,例如:
$builder
->add('password', RepeatedType::class, [
'type' => PasswordType::class,
'invalid_message' => 'The password fields must match.',
'first_options' => ['label' => 'New password', 'attr' => ['placeholder' => 'First placeholder']],
'second_options' => ['label' => 'Repeat new password', 'attr' => ['placeholder' => 'Second placeholder']],
...
])
我使用 Symfony 表单生成器制作重复类型 (RepeatedType) 的密码字段 (PasswordType):
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'required' => true,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
'constraints' => [
new Assert\NotBlank(['message' => "Ce champ est obligatoire."]),
new Assert\Length([
'min' => 8,
'minMessage' => 'Le mot de passe doit comporter plus de {{ limit }} caractères.',
]),
],
'invalid_message' => 'Le mot de passe doit être identique.',
'options' => ['attr' => [
'class' => 'password-field',
'placeholder' => "Mot de passe"
]],
])
但是我想为 2 个密码输入设置 2 个不同的占位符,我不知道该怎么做。
您可以将 attr
属性添加到 first_options
和 second_options
,例如:
$builder
->add('password', RepeatedType::class, [
'type' => PasswordType::class,
'invalid_message' => 'The password fields must match.',
'first_options' => ['label' => 'New password', 'attr' => ['placeholder' => 'First placeholder']],
'second_options' => ['label' => 'Repeat new password', 'attr' => ['placeholder' => 'Second placeholder']],
...
])