0

I have a custom username and password field in my form which is independent from the normal website login.

public function getFormFieldUsername() {
  return [
      '#type' => 'textfield',
      '#title' => 'Username *',
      '#attributes' => ['autocomplete' => 'off'],
    ];
  }

  public function getFormFieldPassword() {
    return [
      '#type' => 'password',
      '#title' => 'Password *',
      '#attributes' => ['autocomplete' => 'off'],
    ];
  }

The '#attributes' => ['autocomplete' => 'off'], doesn't block the auto-fill from the browser tho. Is there a way to achieve that anyways?

  • Did you check that the input field has the autocomplete attribute set to off , in the browser ? – berramou Apr 12 at 11:43
  • 2
    If the attribute is in the HTML, and the browser's still filling it in, you'll need to take it up with the browser's developers, or hack around it. Drupal's only job in this is getting the HTML rendered, after that it can't do anything to control how the browser interprets it – Clive Apr 12 at 12:00
  • Aaah, so Chrome is the culprit. I'll have a look at the link to hack around it. :) – Xyarvius Apr 12 at 12:58

Your Answer

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

Browse other questions tagged or ask your own question.