January 21, 2020: Updated snippet to be simpler and more aggressive.
Overview
In my experience, autocomplete is generally more helpful than harmful but there are times when it just gets in the way. For those times, use this handy snippet to disable this feature.
- Overview
- Using the Snippet
- Autocomplete in Gravity Forms.
- How autocomplete works in different browsers.
Using the Snippet
Confirm that you have Gravity Forms installed and activated and that you’ve installed the snippet. Once you have installed the snippet, you’re good to go! This one’s plug and play!
Autocomplete in Gravity Forms.
By default, Gravity Forms outputs HTML5 fields. The HTML5 spec offers a framework for labeling fields so the browser can automatically complete forms with previously-entered information. In short, you don’t have to do anything for Gravity Forms to activate autocomplete on your forms.
There is an option in Gravity Forms’ Settings that allows you disable HTML5 output. This will disable autocomplete for those fields, but we don’t recommend it. Disabling HTML5 also removes many other useful features, such as automatically displaying a different mobile keyboard when a Phone or Email field is selected. Instead, you can use this snippet to only disable autocomplete while keeping the rest of the HTML5 goodies.
How autocomplete works in different browsers.
Autocomplete behavior differs between browsers. While HTML5 standards dictate how autocomplete should work in general, it leaves some room for interpretation. Browser manufacturers use slightly different implementations for triggering autocomplete, and while the user experience is mostly identical, the technical differences create a situation where a one-size-fits-all solution for disabling autocomplete isn’t possible.
The spec itself states that the autocomplete
attribute can be added to any input
, select
, or textarea
to change the autocomplete behavior of those fields. It furthers states that the use of the off
value should disable autocomplete for that field. This works in many browsers, but not all. Below is a breakdown of how different autocomplete
values are interpreted by different browsers.
off | Works in all browsers except Chrome. Chrome ignores autocomplete="off" for fields that it detects as requesting personal information (i.e. fields with labels like Name, Phone, or Address). It does respect off to non-personal-information fields. |
password | Works in Chrome to completely disable autocomplete. Does not work in other browsers. |
Because of the different behaviors in browsers, our snippet does a quick User Agent check to determine what browser is loading the form. It then assigns the appropriate autocomplete
value for that particular browser. In our testing, autocomplete is disabled in all browsers on both desktop and mobile.
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 46+ essential add-ons for Gravity Forms with support you can count on.
I couldn’t get this to work unfortunately, is the code current?
Hi Russell, this is working for me. Do you have an example I could take a look at on your end?
Hi David,
Thanks for replying this is the form I am trying to stop the autocomplete on but the code didn’t work. Could this be a caching issue?
I am using avada theme.
Thanks
Russell
Hi Russell, I don’t see a link? Go ahead and email me at david at gravitywiz dot com. Include this link so I’ll have some reference to this conversation:
https://gravitywiz.com/disable-autocomplete-gravity-forms/#comment-375841
Hi!
How to disable autocomplete / autofill for a specific form?
Thanks
You’ll want to update the filter names to
gform_form_tag_123
andgform_field_content_123
respectively, where123
is your form ID.This worked beautifully on an old site I’m editing. Thank you so much. : )
Glad to help, Sara!
Is there any way of disabling autocomplete for the honeypot field??
Something I’ve noticed. If you turn off the “Enable Locator button” option, the code no longer functions. Turning it back on makes it work again.
Just fyi.
Interesting.. when I add another single text field, it stops working. Even if I add a specific form and field.
Hi, How to disable autocomplete / autofill for a specific field?
Thanks a lot.
Hi Mart, same snippet but update the filter name to target your form and field:
gform_field_content_FORMID_FIELDID
.So where does this bit go please? I need to disable it on feild 9, on form 8. So how can I do that please? Also when the time comes, how would I then ad additional fields on other forms please? field: gform_field_content_FORMID_FIELDID. ‘, ‘ autocomplete=”off”>’, $form_tag ); } return $form_tag; } add_filter( ‘gform_field_content’, ‘gform_form_input_autocomplete’, 11, 5 ); function gform_form_input_autocomplete( $input, $field, $value, $lead_id, $form_id ) { if ( is_admin() ) return $input; if ( GFFormsModel::is_html5_enabled() ) { $input = preg_replace( ‘/<(input|textarea)/', '
This would go in your theme’s functions.php file. More instructions on snippet installation here: https://gravitywiz.com/documentation/snippet-troubleshooting/
I got google Chrome to NOT do autofill by making the following changes to the code provided:
1) Removed the HTML5 condition for the code
2) Changed autocomplete=off to autcomplete=something-new per the recommendations I found here: https://stackoverflow.com/questions/47775041/disable-autofill-in-chrome-63
FYI, that Stack Overflow link/lead was provided in a different comment.
Anyway, now it’s working for me the way I want. If there are any disadvantages to removing the HTML5 condition for the code, let me know, but so far so good.
I’m pasting the code I’m using in the “Code” box, since it’s not allowed in the comment section.
Hi Dave F, could you re-share your code via a snippi? Our “Code” box is no longer supported (now removed).
Hello Dave, I would really like to see the plugin snippet as its not displayed here. By the way does it still work?
This did not work for google chrome. Autofill was still working when I uploaded the script and tested it.
Autofill is different than autocomplete and Chrome does not respect the autocomplete attribute for autofill.
Try this it worked on some of my multi-page form but on the page where I had gravity-pdf preview it had no effect on the remaining address and email fields and in fact those reset the preview proving where this autofill was messing with earlier entries on other pages of the form. I still don’t know how to block it from happening it makes my extensive multi page form useless.
https://organicweb.com.au/16112/wordpress/disable-chrome-autofill/
Latest on it I could find https://stackoverflow.com/questions/47775041/disable-autofill-in-chrome-63
Hello. How can I disable the autocomplete in a specific field? I badly need it.
Replied via support. :)
Hi, I am interested in using this code in my theme to disable Auto Complete in my Gravity Forms but the theme’s function file is limited and states not to enter any coding in it. Is there an alternative way please?
Thank you
Sure, Dave. This plugin will let you install snippets from your admin. https://wordpress.org/plugins/code-snippets/
Thanks for the reply David but unfortunately it didn’t work
Is there any other way of making this work please?
Hey David, How can I use this feature for specific fields in a form? It is necessary in conjunction with Auto-complete perk so that the browser auto-fill does not interfere with that function (especially on mobile). Alternatively to automatically disable browser auto-fill for all fields where auto-complete perk is active.
Hey Sam, drop me a line via support and I’ll update GP Auto-complete to automatically disable the HTML autocomplete.
Is there a way to block a user from copying and pasting into a field?
It does appear to be possible but I’m not aware of a Gravity-Forms-specific solution.
Any way this could be modified for autocapitalize? And preferably to turn off autocapitalize AND autocomplete for a specific field (like email address, especially for mobile users)?
Sure, Cieran. Duplicate the snippet and everywhere you see “autocomplete”, replace it with “autocapitalize”.
Is there a way to disable autocomplete for a field type (like the date field) or for a specific field in a specific form?
We don’t have a ready solution for this but thanks for the suggestion. We’ll see if other users need this too and update the article accordingly.
Is there a solution for this? I need it too. As soon as you click in the box of the date field, I got all kind of auto fill options that has nothing to do with a date. Because of the list, it is hard to actually see the calendar too. Weird that there are not a lot more people having this issue.
Hi Marnick, this snippet should work for Date fields, but it will also work for all other fields. If you find that it isn’t working, feel free to share a URL where I can see the issue.
I’ve had a look at your video where it shows your Perk – Auto Complete, http://www.screencast.com/t/RFsnB5xrg, however I have the perks packaged installed and I can’t find that perk anywhere. I can’t even find it through your site’s search.
Where can I download it?
Hi Jordan/David,
I hope this message finds you! I put the code into the functions.php, enabled HTML5, but it doesn’t seem to be working for me. Anything I can do to get this to work? I’m using the following versions:
PHP Version 5.3.29 MySQL Version 5.1.56 WordPress Version 4.2.2 Gravity Forms Version 1.9.9
Thanks!
Also, here’s the site. Thanks again! http://www.wvsun.org/solar-coops/charleston-solar-co-op/
Hi Grant, try getting the snippet from the “raw” version. It looks like the formatted version above isn’t quite right.
https://gist.githubusercontent.com/ronalfy/6184373/raw/gravity-forms-disable-autocomplete.php
Thanks for replying David! Unfortunately I already did use the raw version, and it didn’t work for me. Any other thoughts on a fix?
I didn’t realise GFs had autocomplete. Can you advise how to use this as I can see nothing about it?
Nigel
This article is for browser-powered auto complete where previously submitted data is saved by the browser and then suggested to the user when they begin to type into fields. Similarly, you can override the default auto-complete with your own and provide your own data to auto-suggest. I have a perk in the works which you can see here:
http://www.screencast.com/t/RFsnB5xrg
If you’d like to give this perk a try, pick up a copy of Gravity Perks and drop me a line via the support form requesting access to this unreleased perk.
I didn’t even realize GF had autocomplete. I have never seen it in action. Is this on by default?