Hello, I would like to know, how I can disable HTML form input field auto-complete, done by chrome and other majore browsers.
Thanks
You can have two ways to stop auto-complete of forms input field by:
1. Add autocomplete="off" onto <form> element
<form method="post" action="/form" autocomplete="off">
First name:<input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
</form>
2. OR you can disable auto complete on a particular form input field
<input type="email" name="email" autocomplete="off">
Any of the above will work and you can use it depending on your requirements.
3. instead of setting autocomplete=off
, you could also have your form field names be randomized by the code that generates the page and on server-side, once form is submitted, you can strip that random generated code to get values.
This approach also helps you from XSRF attack, as hacker cannot know your fields names
Above solution works but chrome will still not turn off auto-complete for password fields so solution for Chrome is to add
autocomplete="new-password"
to the input type password.
<form name="myForm"" method="post">
<input name="user" type="text" />
<input name="pass" type="password" autocomplete="new-password" />
<input type="submit">
</form>
Also, to note, this will work for other type of fields also in chrome, something like this
<input name="name" type="text" autocomplete="rutjfkde">
hope it helps.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly