Disable Autocomplete for Gravity Forms
Disable autocomplete for your Gravity Forms with this copy-and-paste snippet.
January 21, 2020: Updated snippet to be simpler and more aggressive.
In my experience, autocomplete can be a hero. It saves time and boosts accessibility, especially for folks with cognitive disabilities, by letting assistive tech predict and fill in form fields.
However, when security and privacy are paramount—such as with student forms on public computers—autocomplete can become a nuisance, potentially exposing sensitive information.
Not to mention when autocomplete simply gets in the way, adding unnecessary noise to the form-filling process.
For those moments when autocomplete isn’t quite the ally you need, here’s our trusty snippet to disable it in Gravity Forms.
- Using the snippet
- What is the autocomplete attribute?
- Autocomplete in Gravity Forms
- 1, 2, 3 reasons to use the snippet
- How autocomplete works in different browsers
Using the snippet
This one is plug and play: once you have Gravity Forms installed and activated, just install the snippet and you’re good to go!
This snippet will apply to all forms and fields in your site. If you’d like to only apply this to specific forms and/or specific fields, let us know in the comments.
What is the autocomplete attribute?
The HTML autocomplete
attribute lets you specify which permissions the user agent (in this case, the user’s browser) has for providing autofill to some field values. It can also provide guidance for what type of information is expected for that field.
When enabled, this feature enables browsers to remember what has been typed in forms before and suggest those same inputs again for similar fields.
Autocomplete in Gravity Forms
Back in 2021, Gravity Forms 2.5 was released, and it added the ability to specify an autocomplete property for some fields:
- Single Line Text
- Drop Down
- Number
- Name
- Phone
- Address
This was done with the intent to help developers comply with the Web Content Accessibility Guidelines (WCAG) 2.1 AA by indicating the input purpose for a field.
If you are looking for a quick way to turn autocomplete off for one of those seven field types, you could write the `off` property into that setting. That is a stop-gap solution though.
1, 2, 3 reasons to use the snippet
- Left out in the cold: That solution doesn’t apply to all field types.
- Date fields, for example, are a notable exclusion. Imagine you’re registering for an enchanting upcoming event. You focus on the Date field to select the day you want to attend, and your browser sends the datepicker all the way back to the last century because it auto completed the date with your birthday. Ouch.
- Ghosted: Some browsers, like Chrome, ignore the
off
property on many occasions. - Privacy power-up: For truly private forms, particularly those that may be completed on public or shared computers, disabling autocomplete for all fields is clutch. That is exactly what this snippet does.
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 is hard to achieve.
That’s why we turn to a bit of code magic. 🪄
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 further 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 most browsers except Chrome and Firefox. Both browsers ignore autocomplete="off"
for fields that they detect as requesting personal information (i.e. Name, Phone, or Address) or login credentials. For all other information fields, off
is respected by both.
new-password
: Works in Chrome and Firefox to completely disable autocomplete. Does not work in other 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, except for Safari, on both desktop and mobile.
Find a browser where autocomplete is still active with the snippet installed? Let us know!
Thanks for this terrific snippet. FYI, it is easy to customize it so that it only runs for a certain form by adding the form ID after gform_form_tag_# (where # is the form ID):
https://docs.gravityforms.com/gform_form_tag/
Then do the same thing for gform_field_content, e.g., gform_field_content_# (where # is the form ID). That filter also allows specifying the field ID if desired.
https://docs.gravityforms.com/gform_field_content/
Best regards, Rob
Hey Rob,
Glad you’re enjoying the snippet, and thanks for sharing this super handy tip! 😊
This worked! I just wanted to spread the love and boost this post as it should be at the top of search results for removing autofill on Gravity Forms. Thanks!
Hi Kiley,
Thanks for the love. Glad to hear it’s working for you! 🧙♂️
This doesn’t work on iPhone using Safari
Hi Casey,
I just did a test, and it appears to work on iPhone using Safari. Could you please check if the snippet is properly added to the website? You can contact us via our support form if you can still not get it working for you so we can assist you further.
Best,
Hi there. Thanks for your job. I would like to keep the autocomplete on all field, a part from email confirmation field. Any hint? thx again
Hi Matteo,
This will require some digging by our developers. You can reach out via our support form if you have an active Gravity Perks license.
Best,
I am looking for this same functionality and assume many others are as well. Seems like it would be a very common need to not autofill an email confirmation field. Thanks!
Hi Cathy,
Here’s a Gravity Forms Forum Post with some information on this. I hope this helps.
Best,
So this did not work. I copied the code to the functions.php to the bottom of the file. I also tried Code Snippets still did not work. I know this is a blank statement, and impossible to troubleshoot. But basically, regardless of the browser (chromium or whatever), the cached address list still shows up. I’m not going to put the URL publicly. But I do have an account with your so logs should be there. Let me know what else I can do to help.
Hi,
I just did a test with the code, and it works as expected. I’ve sent you a reply via email.
Best,
Problem is that it doesn’t work with the latest Microsoft Edge Based of Chromium. I tested in a bunch of other browsers, no issues. Here is what the useragent returns Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.56
Hi,
I’m still unable to recreate this issue. It works also on the latest version of Egde. I’ve sent you an email with more information on my findings.
Best,
I am getting this error.
‘Your PHP code changes were rolled back due to an error on line 717 of file /www/wp-content/themes/enfold/functions.php. Please fix and try saving again.
syntax error, unexpected ‘<‘, expecting end of file’
Hi John,
It sounds like you might be having some trouble with installing the snippet. Please refer to our article on snippet troubleshooting for details on installing our snippets.
https://gravitywiz.com/documentation/snippet-troubleshooting/
Best,
Hello friends! Thank you for the code.
I couldn’t make it work yet. I’m running DIVI. I’ve followed their instructions on how to add code snippets to their theme (by using a code snippet plugin) but it doesn’t seem to be working.
Any advice? Moses
Hi Moses,
If you’re a Gravity Perks customer, we’re happy to dig into this for you. Drop us a line.
Is there a way to add autocomplete on one particular form and field?
Hello Alice, to add to one form, you’ll want to update the filter names to gform_form_tag_123 and gform_field_content_123 respectively, where 123 is your form ID. As for a particular form and field, update the filter name to target your form and field: gform_field_content_FORMID_FIELDID.😃
Hi Ryan, thanks for your code, I’m able to remove the auto fill on form with your code above but change autocomplete=’off’ to autocomplete=’new-password’
and I also have try using this code and works on all page (at least on my end) $(‘input’).attr(‘autocomplete’,’new-password’);
I’m not a real developer, just share if some one sturgle with this issue :)
This worked, thanks!
Here is an even easier way that is more customer friendly.
Add a class to the gravity form’s “Custom CSS Class” field… something like “no-autocomplete”.
Then add the following to your site’s JS file:
jQuery(document).ready(function($) { $(“.no-autocomplete input”).attr(‘autocomplete’, ‘off’); });
Is there an easy way to disable the autofill for multiple forms? I saw how to apply it to an individual form, but didn’t see a reply for applying it to more than one.
Hello Trey, This is a great question. You may want to check out our documentation here on how to apply class-based snippets to the same form. 😃
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?
[…] Wiz shows you how to disable browser autocompletes in a recent […]
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?
[…] another handy Gravity Forms snippet from Gravity Wiz: Disable auto-complete for your […]