Formbuilder RepeatedType PasswordType占位符

时间:2016-08-23 16:40:39

标签: forms symfony silex formbuilder

我使用Symfony formbuilder来制作类型为repeat(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个不同的占位符,我不知道该怎么做。

1 个答案:

答案 0 :(得分:3)

您可以将attr属性添加到first_optionssecond_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']],
        ...
    ])