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.

  1. Using the snippet
  2. What is the autocomplete attribute?
  3. Autocomplete in Gravity Forms
  4. 1, 2, 3 reasons to use the snippet
  5. 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
  • Email

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

  1. 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.
  2. Ghosted: Some browsers, like Chrome, ignore the off property on many occasions.
  3. 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!

Comments

  1. Kiley
    Kiley November 8, 2024 at 12:02 pm

    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!

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff December 12, 2022 at 4:28 am

      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,

  2. matteo
    matteo July 27, 2022 at 12:23 pm

    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

    Reply
    1. Dario Space
      Dario Space July 27, 2022 at 12:29 pm

      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,

    2. Cathy
      Cathy August 1, 2022 at 7:15 pm

      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!

  3. PWIA Webmaster
    PWIA Webmaster February 10, 2022 at 11:13 pm

    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.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff February 11, 2022 at 4:31 am

      Hi,

      I just did a test with the code, and it works as expected. I’ve sent you a reply via email.

      Best,

    2. PWIA Webmaster
      PWIA Webmaster February 24, 2022 at 1:50 am

      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

    3. Samuel Bassah
      Samuel Bassah Staff February 24, 2022 at 8:19 am

      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,

  4. John joseph Raslavsky
    John joseph Raslavsky June 2, 2021 at 8:56 pm

    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’

    Reply
  5. Moses
    Moses March 23, 2021 at 4:43 pm

    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

    Reply
    1. Ryan Donovan
      Ryan Donovan August 11, 2020 at 5:04 pm

      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.😃

  6. Ekas
    Ekas August 6, 2020 at 10:10 am

    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 :)

    Reply
  7. Eric Kazda
    Eric Kazda May 7, 2020 at 4:03 pm

    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’); });

    Reply
  8. Trey Gallant
    Trey Gallant April 20, 2020 at 5:56 pm

    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.

    Reply
    1. David Smith
      David Smith Staff November 4, 2019 at 5:04 pm

      Hi Russell, this is working for me. Do you have an example I could take a look at on your end?

    2. Russell Davies
      Russell Davies November 4, 2019 at 5:13 pm

      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

    1. David Smith
      David Smith Staff October 3, 2019 at 12:00 pm

      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.

  9. Lee Fuller
    Lee Fuller May 12, 2019 at 12:27 pm

    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.

    Reply
    1. Lee Fuller
      Lee Fuller May 12, 2019 at 1:04 pm

      Interesting.. when I add another single text field, it stops working. Even if I add a specific form and field.

    1. David Smith
      David Smith Staff February 27, 2019 at 10:49 am

      Hi Mart, same snippet but update the filter name to target your form and field: gform_field_content_FORMID_FIELDID.

    2. ben Horle
      ben Horle January 3, 2020 at 7:07 am

      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)/', '

  10. Dave F
    Dave F November 29, 2018 at 4:59 pm

    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.

    Reply
    1. Ewomazino Donald
      Ewomazino Donald August 21, 2019 at 11:14 am

      Hello Dave, I would really like to see the plugin snippet as its not displayed here. By the way does it still work?

    1. David Smith
      David Smith Staff April 19, 2017 at 7:34 am

      Autofill is different than autocomplete and Chrome does not respect the autocomplete attribute for autofill.

    2. Ed
      Ed March 22, 2018 at 11:24 am

      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/

  11. Dave
    Dave January 11, 2017 at 10:24 am

    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

    Reply
  12. Sam Mitzmann
    Sam Mitzmann December 22, 2016 at 2:38 am

    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.

    Reply
    1. David Smith
      David Smith Staff December 23, 2016 at 3:48 pm

      Hey Sam, drop me a line via support and I’ll update GP Auto-complete to automatically disable the HTML autocomplete.

  13. Cieran
    Cieran November 17, 2016 at 7:04 am

    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)?

    Reply
    1. David Smith
      David Smith Staff November 17, 2016 at 8:36 am

      Sure, Cieran. Duplicate the snippet and everywhere you see “autocomplete”, replace it with “autocapitalize”.

  14. Sam
    Sam July 6, 2016 at 9:08 am

    Is there a way to disable autocomplete for a field type (like the date field) or for a specific field in a specific form?

    Reply
    1. David Smith
      David Smith Staff July 14, 2016 at 7:56 pm

      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.

    2. Marnick
      Marnick December 6, 2019 at 2:19 am

      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.

    3. David Smith
      David Smith Staff December 9, 2019 at 9:39 am

      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.

  15. Grant
    Grant June 3, 2015 at 5:18 pm

    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!

    Reply
    1. Grant
      Grant June 5, 2015 at 9:40 am

      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?

    1. David Smith
      David Smith Staff November 3, 2014 at 8:58 am

      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.

  16. Weekly Roundup: October 31, 2014 &ndash; Sell with WP October 31, 2014 at 2:01 am

    […] another handy Gravity Forms snippet from Gravity Wiz: Disable auto-complete for your […]

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Snippet

Disable Autocomplete for Gravity Forms

This field is for validation purposes and should be left unchanged.