---
title: Autocomplete, clearing form values and Drupal form fields
description: Some browsers like to be helpful and help by remembering certain form fields.  I was having a problem with Firefox auto-populating my some of my form fields (specifically field type 'password' and 'password_confirm') in a custom module I wrote.
---

[Blog ](https://www.metaltoad.com/blog)

# [Autocomplete, clearing form values and Drupal form fields](https://www.metaltoad.com/blog/autocomplete-clearing-form-values-and-drupal-form-fields)

 Written by [Metal Toad Staff](https://www.metaltoad.com/blog/author/metal-toad-staff) | Feb 20, 2009 12:00:00 AM

 Filed under:

- [Drupal](https://www.metaltoad.com/help/drupal)

Some browsers like to be helpful and help by remembering certain form fields. I was having a problem with Firefox auto-populating my some of my form fields (specifically field type 'password' and 'password_confirm') in a custom module I wrote.

After some consternation, I referred to our cardboard cutout Han Solo, who helped me to remember a bit more about form options and field auto-completion.

To fix this problem just add an #attribute of 'autocomplete' => 'off', e.g.

```
<?php
/**
 * Implementation of hook_form()
 */
function mymodule_form() {
	$form['old_password'] = array(
		'#title' => t('Old Password'),
		'#type' => 'textfield',
		'#attributes' => array('autocomplete' =>'off'),
		'#required' => TRUE,
	);
	$form['new_password'] = array(
		'#type' => 'password_confirm',
		'#attributes' => array('autocomplete' =>'off'),
		'#required' => TRUE,
	);
	$form['submit'] = array(
		'#type' => 'submit',
		'#value' => t('Submit'),
	);
	$form['clear'] = array(
		'#type' => 'button',
		'#value' => t('Clear'),
		'#attributes' => array('onclick' => 'this.form.reset(); return false;'),
	);
	return $form;
}
```

The example above also includes a nifty way to clear out form fields via javascript in the $form['clear'] element.

[View full post](https://www.metaltoad.com/blog/autocomplete-clearing-form-values-and-drupal-form-fields)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Metal Toad Staff"
  },
  "dateModified" : "2023-12-06T23:21:15.200Z",
  "datePublished" : "2009-02-20T00:00:00Z",
  "headline" : "Autocomplete, clearing form values and Drupal form fields",
  "image" : {
    "@type" : "ImageObject",
    "height" : 500,
    "url" : "https://6104926.fs1.hubspotusercontent-na1.net/hubfs/6104926/Imported_Blog_Media/Metal_Toad_blog_generic-Aug-11-2023-09-59-28-6540-PM.jpg",
    "width" : 870
  },
  "mainEntityOfPage" : "https://www.metaltoad.com/blog/autocomplete-clearing-form-values-and-drupal-form-fields",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60.0,
      "url" : "https://6104926.fs1.hubspotusercontent-na1.net/hubfs/6104926/social-suggested-images/6104926.fs1.hubspotusercontent-na1.nethub6104926hubfsMetal_Toad_Logo_orange_horizontal-50-1.jpg",
      "width" : 240.00002
    },
    "name" : "Blog"
  }
}
```