January 21, 2020: Updated snippet to be simpler and more aggressive.
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 inspired by @ronalfy to disable this feature.
<?php | |
// Disable auto-complete on form. | |
add_filter( 'gform_form_tag', function( $form_tag ) { | |
return str_replace( '>', ' autocomplete="off">', $form_tag ); | |
}, 11 ); | |
// Diable auto-complete on each field. | |
add_filter( 'gform_field_content', function( $input ) { | |
return preg_replace( '/<(input|textarea)/', '<${1} autocomplete="off" ', $input ); | |
}, 11 ); |
How do I get started?
- This will work with even older versions Gravity Forms but that’s no excuse not to be running the latest version.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Copy and paste the snippet into your theme’s functions.php file.
- Once you have installed the snippet, you’re good to go! This one’s plug and play.
If you use it and like it, let us know!
This snippet will apply to all forms and all fields. If you’d like to only apply this to specific forms and/or specific fields, let us know in the comments.
Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 32+ essential add-ons for Gravity Forms with support you can count on.
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. 😃