【发布时间】:2020-06-03 19:45:31
【问题描述】:
我正在使用ResetPassword 系统,这是用户在收到电子邮件后输入新密码的页面。
基本上我要做的就是在视图页面中分离RepeatedType!
在视图中(.twig)我有:
{{ form_start(resetForm) }}
{{ form_widget(resetForm.plainPassword) }}
<button>Reset password</button>
{{ form_end(resetForm) }}
代替
{{ form_widget(resetForm.plainPassword) }}
我想将它们分开并制作类似的东西:
{{ form_widget(resetForm.plainPassword[1]) }}
{{ form_widget(resetForm.plainPassword[2]) }}
这可能吗?如果是,那么正确的语法是什么?
这是ChangePasswordFormType.php的代码:
class ChangePasswordFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => [
'attr' => [
'class' => 'form-control form-control-sm',
],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
'label' => 'New password :',
],
'second_options' => [
'attr' => [
'class' => 'form-control',
],
'label' => 'Repeat it :',
],
'invalid_message' => 'The password fields must match.',
// Instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
])
;
}
【问题讨论】:
标签: php symfony symfony-forms