重置密码时 Invalid_message 未以正确格式显示

发布于 2025-01-11 09:50:51 字数 1550 浏览 0 评论 0原文

我的重置表单看起来像是

 $builder
            ->add('plainPassword', RepeatedType::class, [
                'type' => PasswordType::class,
                'first_options' => [
                    'attr' => ['autocomplete' => 'new-password'],
                    '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' => ['autocomplete' => 'new-password'],
                    'label' => 'Repeat Password',
                ],
                '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,
            ])
        ;

在执行测试,以检查我是否输入了错误的密码,而不是网页的外观。问题是新密码输入框后显示无效消息(如下所示)。我希望“密码字段必须匹配”位于新密码之上

Reset your password
New password
The password fields must match.
|INPUTBOX|
Repeat Password|INPUTBOX|

My reset form looks like

 $builder
            ->add('plainPassword', RepeatedType::class, [
                'type' => PasswordType::class,
                'first_options' => [
                    'attr' => ['autocomplete' => 'new-password'],
                    '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' => ['autocomplete' => 'new-password'],
                    'label' => 'Repeat Password',
                ],
                '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,
            ])
        ;

I was performing testing to check if I enter wrong password than how the web page looks like. The problem is the invalid message shows after new password input box (like below). I want the "The password fields must match" to be on top of New Password

Reset your password
New password
The password fields must match.
|INPUTBOX|
Repeat Password|INPUTBOX|

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦明 2025-01-18 09:50:51

在你的树枝页面中,你应该显示这样的表单:

{{ form_start(form) }}
{{ form_label(form.password.first) }}
{{ form_errors(form.password.first) }}
{{ form_widget(form.password.first) }}
//other fields
{{ form_end(form) }}

in your twig page you should display the form like that:

{{ form_start(form) }}
{{ form_label(form.password.first) }}
{{ form_errors(form.password.first) }}
{{ form_widget(form.password.first) }}
//other fields
{{ form_end(form) }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文