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|
CodePudding user response:
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) }}
CodePudding user response:
Maybe you could try rendering your form like this? Thus, errors will be displayed above the password fields.
{{ form_start(form) }}
{{ form_errors(form.plainPassword.children['first']) }}
{{ form_errors(form.plainPassword.children['second']) }}
{{ form_widget(form.plainPassword.children['first']) }}
{{ form_widget(form.plainPassword.children['second']) }}
{{ form_end(form) }}
Here is the documentation for it