0

My problem is when have a pre-filled input field, Safari will override the value. Chrome seems to be doing fine.

Here is what I have tried:

<input autocomplete="off" type="email" id="email" name="email" value="someemail@email.com">

But still Safari auto fill manager will override the "someemail@email.com" with something already save by the auto fill manager.

I have searched the internet and apparently autocomplete="off" doesn't work in most browsers anymore, even though I user HTML5. Is that true or is there some solution to that?

Cudos
  • 5,733
  • 11
  • 50
  • 77

1 Answers1

2

I think the most cross-browser way to do it, although a bit painfull server-side, would be to "randomize" part of the name of your controls by concatenating it with session-specific data.

so, before rendering your fields, concatenate the name with a random value like a hash or even a timestamp in order to get something like this:

<input type="email" id="email" name="email20140618135501.255" value="someemail@email.com">

the most important thing is to store this value in a session variable that way you can use the same value on each and every field, but most important you can use it to get the value of that field after POST request.

But it's important to note that you shouldn't choose on behalf of your users whether to use autocomplete or not unless you know you're dealing with sensitive information... or as suggested by Colin's remark, if you know for sure that autocomplete might be totally useless or even counter-productive on that field.

Laurent S.
  • 6,816
  • 2
  • 28
  • 40
  • 2
    This is a good approach. Worth noting "choosing on behalf of your users" is a lot more complicated than it looks. Say you're building an admin panel or a CRM system. Your users will be maintaining lots of *other people's* email addresses. The last thing they want is their browser to autocomplete their *own* email address, possibly overwriting the data already in the form. – Colin Pickard Jun 18 '14 at 12:18
  • I agree with you colin and adited my answer that way. The situation you describe is indeed a good one for choosing to turn auto-complete off on that field. Note that such users might also disable auto-complete by themselves, but in that case that would also disable it for other sites where they might want it :-) – Laurent S. Jun 18 '14 at 12:23
  • @ColinPickard You are spot on. This is for a backend where the manager browse through different users information and edit their info. – Cudos Jun 18 '14 at 12:33