0

I'm encountering the bug described at "Login form error message is redundant and does not make sense". In short, if a user enters invalid credentials once, an inline error message appears on the user login page. When the user enters valid credentials and successfully logs in, the user sees an error message at the top of the screen (e.g., "1 error has been found: username"), but that is no longer correct.

According to this blog post one can disable inline form errors for a particular form by adding $form['#disable_inline_form_errors'] = TRUE; to the form definition, and I have seen that code snippet elsewhere, too. But I can't find any instructions for implementing it. Does anyone have an example?

1 Answer 1

1

The core issue you linked to has a patch that is apparently working, so it may be easier to patch with Composer instead of adding code to a custom module.

But, if you want to use the $form['#disable_inline_form_errors'] = TRUE;, this is what you can do:

First, create a custom module. You need to follow the instructions on the first four pages:

  • Getting Started - Background & Prerequisites
  • Prepare a Module skeleton
  • Naming and placing your Drupal module
  • Let Drupal know about your module with an .info.yml file

Then, in the MYMODULE.module file, add this code:

/**
 * Customize the user login form.
 */
function MYMODULE_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form['#disable_inline_form_errors'] = TRUE;
}

What this code does is use hook_form_alter to target the user login form. Lots of Drupal's form behaviors can be customized in this way.

You then need to go to the module administration page and enable your custom module.

1
  • Thanks so much, Patrick! I ended up patching with drupal.org/project/drupal/issues/2880011#comment-13666816, and it worked! I added $form['#disable_inline_form_errors_summary'] = TRUE; to my theme file, and the problem is gone. I appreciate the time you took to write that clear explanation!
    – sjhuskey
    Feb 13, 2021 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.