Last active
March 28, 2022 19:41
-
-
Save ronalfy/6184373 to your computer and use it in GitHub Desktop.
Disable autocomplete on the front-end for Gravity Forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gform_form_tag', 'gform_form_tag_autocomplete', 11, 2 ); | |
function gform_form_tag_autocomplete( $form_tag, $form ) { | |
if ( is_admin() ) return $form_tag; | |
if ( GFFormsModel::is_html5_enabled() ) { | |
$form_tag = str_replace( '>', ' 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)/', '<${1} autocomplete="off" ', $input ); | |
} | |
return $input; | |
} | |
?> |
Doesn't work in Safari. Form inputs still autocomplete/autofill.
This doesn't appear to be working any more. Additionally the HTML5 checkbox you mentioned on your blog is no longer there.
Changing the code to the example below worked for me.
Additionally Chrome doesn't always respect this setting. Setting the value to something Chrome doesn't understand like autocomplete="asdf"
breaks/disabled the autocomplete feature.
add_filter( 'gform_form_tag', 'gform_form_tag_autocomplete', 11, 2 );
function gform_form_tag_autocomplete( $form_tag, $form ) {
if ( is_admin() ) return $form_tag;
$form_tag = str_replace( '>', ' 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;
$input = preg_replace( '/<(input|textarea)/', '<${1} autocomplete="off" ', $input );
return $input;
}
?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What file do I add that code to? Or do I create a new php file and where do I put it? Thanks.