Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top