1

I am using the core user-register-form to let users register to my site. When I first want to register a new account the form is displayed as followed:

enter image description here

Now, when I enter credentials and submit the form, the user is created. I can login and out with the created user.

However, if I want to register ANOTHER new account the form automatically fills in the e-mail and username of the user I just created.

enter image description here

I have tried several things that did not solve the problem:

  • Clear Drupal cache
  • Close browser and re-open
  • Kill browser and re-open
  • Open incognito browser
  • Clear browser cache
  • Disabled browser auto-fill

I also tried clearing the inputs using jQuery val(''); but then the form doesn't submit properly.

I assume this has something to do with drupal core? Please advice!

2

I found a solution thanks to the Drupal Community

Apparently this is defined in the core of Drupal: core/modules/user/src/RegisterForm.php

The following should be set to FALSE

// For non-admin users, populate the form fields using data from the browser.
    if (!$admin) {
      $form['#attributes']['data-user-info-from-browser'] = TRUE;
    }

However it would be better to not mess with the core values and write a form_hook_alter instead in your theme file:

function MYTHEME_form_alter( &$form, &$form_state, $form_id ) {
  if ( TRUE === in_array( $form_id, array( 'user_register_form') ) ) {
    $form['#attributes']['data-user-info-from-browser'] = FALSE;
  }
}

This solved the problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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