MozillaZine

How can a website developer disable autocomplete in forms?

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Throckmorton
 
Posts: 10
Joined: July 7th, 2005, 7:07 am

Post Posted July 7th, 2005, 7:16 am

How can I design a web form that FireFox will not try to autocomplete?

For IE, I can add the parameter autocomplete="off" to either the <form> tag or the individual <input> tags but that doesn't disable autocomplete for FireFox.

What will?

Thank you.

Throckmorton
 
Posts: 10
Joined: July 7th, 2005, 7:07 am

Post Posted July 13th, 2005, 12:06 pm

Anyone?

Vectorspace
Moderator

User avatar
 
Posts: 14455
Joined: November 27th, 2003, 4:50 am
Location: Warwickshire, UK

Post Posted July 13th, 2005, 12:25 pm

Moving to Web Development - most users here are not web developers, so there will be more people who can help you there.
"All things being equal, the simplest answer is usually the correct one" - Occam's Razor
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0

Unarmed
 
Posts: 4941
Joined: July 31st, 2003, 1:26 pm

Post Posted July 13th, 2005, 12:30 pm

<code>autocomplete="off"</code> on the form element works for me.

dakboy
 
Posts: 3451
Joined: November 30th, 2002, 12:30 pm

Post Posted July 13th, 2005, 12:38 pm

You can't force it to be disabled, you can only suggest it using what Unarmed posted. You can use that attribute in each input field as well. It will result in invalid HTML though. And the user can theoretically override it.

There are articles online (use Google) as well that can help.

old np
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted July 13th, 2005, 12:48 pm

Note that autocomplete=off in Firefox disables STORING data for that form, NOT retrieval. So if you had stored data, then added autocomplete=off, your stored data will remain and will autocomplete, but no new data will be added.

Unarmed
 
Posts: 4941
Joined: July 31st, 2003, 1:26 pm

Post Posted July 13th, 2005, 12:58 pm

Firefox only honors <code>autocomplete="off"</code> on the form, not individual elements (unlike IE).

Nanobot

User avatar
 
Posts: 578
Joined: April 28th, 2004, 7:25 pm
Location: California

Post Posted July 13th, 2005, 1:15 pm

As a website developer, you shouldn't try to control the user's browser interface. Trying to do so will practically always require nonstandard code, can always be overridden, and is just annoying.

old np
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted July 13th, 2005, 1:39 pm

Nanobot wrote:As a website developer, you shouldn't try to control the user's browser interface. Trying to do so will practically always require nonstandard code, can always be overridden, and is just annoying.

I don't see anything wrong with autocomplete=off when used in certain situations such as:
a) Credit card number entry
b) Entry that would likely not be repeated (such as a call centre rep entering a caller's ID number)
c) Fields from the same server with the same name, but mean different things on different pages (ex: when a moderator wants to add a user, they don't want their own username to autocomplete)

Throckmorton
 
Posts: 10
Joined: July 7th, 2005, 7:07 am

Post Posted July 13th, 2005, 2:06 pm

Nanobot wrote:As a website developer, you shouldn't try to control the user's browser interface. Trying to do so will practically always require nonstandard code, can always be overridden, and is just annoying.


In your opinion... But there are obviously circumstances you have not considered. For example, my situation:

I have 4 moderators on a phpBB forum I administer. I have installed the Moderator Control Panel so my moderators can edit user's information. The User Administration screen includes, among other things, the ability to change a user's User Name or reset a user's Password.

With FireFox's incorrect handling of this situation, the moderator's own username and password are incorrectly applied to the user's fields as soon as the page is loaded, potentially destroying a user account if not reset.

This isn't about trying to control a user's experience. This is about trying to resolve an issue FireFox incorrectly handles.

To automatically fill in the user's Username and Password on a login screen is fine. To do so on a data screen like this not only wrong, it is unacceptable. You are more likely to corrupt the data than save the user time.

In the future, Nanobot, it might be wise to understand what you are offering an opinion about. Your response not only didn't help with my question, it unnecessarily annoyed me. I need help with a technical problem, not a critique of my web design philosophy.

jqp

User avatar
 
Posts: 5070
Joined: November 17th, 2004, 10:56 am
Location: In a box

Post Posted July 13th, 2005, 2:15 pm

Would it work to add a script to clear out text fields that are supposed to be empty?

Code: Select all
window.onload = function() {
inputs = document.getElementsByTagName("input");
 for(var i = 0; i < input.length; i++) {
  if(inputs[i].type == "text" || !input[i].getAttribute("type")) {
/* make this more specific to get only the inputs you want */
  inputs[i].value = "";
  }
 }
}

That would only work if autocomplete happens BEFORE any onload events, and onload happens AFTER autocomplete... (it should, if I'm right...)
I agree - put autocomplete=off on the form element, too, for good measure.

Throckmorton
 
Posts: 10
Joined: July 7th, 2005, 7:07 am

Post Posted July 13th, 2005, 2:19 pm

That might work in most cases, jonnyq. It's a good idea.

In my particular situation though, the Username field is supposed to have the username of the account being edited in it. FireFox overwrites this with the username of the Moderator that is modifying the account.

Unarmed
 
Posts: 4941
Joined: July 31st, 2003, 1:26 pm

Post Posted July 13th, 2005, 2:26 pm

Yes, this is a known bug (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=112260" title="Bug 112260 - Password manager silently overwrites form-supplied values">Suite</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=229762" title="Bug 229762 - If username field is prefilled by page to a value that matches a stored signon, pwmgr should prefill password">Firefox</a>). The alternative workaround to futzing with the autocomplete value would be to disallow Firefox from saving your username/password for the forum.
Last edited by Unarmed on July 13th, 2005, 2:29 pm, edited 1 time in total.

JaredM
 
Posts: 3826
Joined: November 14th, 2004, 4:41 am
Location: Alberta, Canada

Post Posted July 13th, 2005, 2:27 pm

Yes this is a constant pain in the arse on my phpbb forums as well... the PHPBB creator actually filed a bug in bugzilla about this lemme see if I can dig it up.

Edit: nm unarmed beat me to it.
I'm moving to Theory, everything works there.
Most issues are solved by going through the Standard Diagnostic

Throckmorton
 
Posts: 10
Joined: July 7th, 2005, 7:07 am

Post Posted July 13th, 2005, 2:37 pm

Here's what I've implemented as a work around:

Add this script:
Code: Select all
<script language="JavaScript" type="text/javascript">
<!--
   function FixFields()
   {
      document.usradm.username.value = document.usradm.temp_username.value;
      document.usradm.password.value = document.usradm.temp_password.value;
   }
// -->
</script>


Add to the <form tag>:
Code: Select all
name="usradm" onsubmit="FixFields()"


Change the "username" and "password" field names to "temp_username" and "temp_password"
Code: Select all
<input class="post" type="text" name="temp_username" size="35" maxlength="40" value="{USERNAME}"{DISABLE_CHANGE} />

<input class="post" type="password" name="temp_password" size="35" maxlength="32" value=""{DISABLE_CHANGE} />


And add hidden fields to receive the values to be submitted:

Code: Select all
<input type="hidden" name="username" value="" />

<input type="hidden" name="password" value="" />


So far, it's been working like a charm.

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 0 guests