4

How do you disable the autocomplete functionality in the major browsers for a specific input (or form field)?

<input type="text" id="fullname" name="fullname" class="form-control" data-required="true" value="<?php echo $_POST['fullname']?>" >

When I open this form I see the value in this input even if I didn't insert any value.

Adriano
  • 2,862
  • 4
  • 25
  • 37

4 Answers4

3

Just use the autocomplete attribute:

<input type="text" autocomplete="off"/>

"This would be useful when a text input is one-off and unique. Like a CAPTCHA input, one-time use codes, or for when you have built your own auto-suggest/auto-complete feature and need to turn off the browser default."

Source : CSS Tricks

Yaje
  • 2,479
  • 14
  • 31
3

I think adding autocomplete="off" would get you an error on most browsers, furthermore, autocomplete="off" is an invalid property.

Try to check the Mozilla Developer Documentation instead.

Adriano
  • 2,862
  • 4
  • 25
  • 37
Nooblike
  • 140
  • 1
  • 10
0

You could generate a random string using javasript or php and add it to the end of an input name, maybe even use a delimiter to split it apart from the actual name.

In php, you could use something like the session_id for this and simply echo it to the end of the name.

<input type="text" autocomplete="off" name="example<?php echo "," . session_id()?>">

You can replace the "," with any delimiter of your choice, so long as it isn't alphanumeric. Then when processing the data submitted, you can remove it from the end of the actual name of the input field.

With a field name always being different, your browser cant autocomplete it.

Source: https://stackoverflow.com/a/218453/12251360

0

Solution 1

<form name="form1" id="form1" method="post" 
          autocomplete="off" action="http://www.example.com/form.cgi">

This will work in Internet Explorer and Mozilla FireFox, the downside is that it is not XHTML standard.

Solution 2

The solution for Chrome is to add autocomplete="new-password" to the input type password.

Example:

<form name="myForm"" method="post">
     <input name="user" type="text" />
     <input name="pass" type="password" autocomplete="new-password" />
     <input type="submit">
</form>

Chrome always autocomplete the data if it finds a box of type password, just enough to indicate for that box autocomplete = "new-password".

This works well for me.

Note: make sure with F12 that your changes take effect, many times browsers save the page in cache, this gave me a bad impression that it did not work, but the browser did not actually bring the changes.

Solution 3

<input type="text" id="fullname" name="fullname" autocomplete="off" class="form-control" data-required="true" value="<?php echo $_POST['fullname']?>"  >

links

Solution 3 Reference : https://stackoverflow.com/a/25496311/6923146

Solution 2 Reference : https://stackoverflow.com/a/40791726/6923146