Disable Autocomplete for a form with Gravity Forms
For convenience, most web browsers save what information you previously submitted on website forms so that the next time you are filling in a form you only need to select the entry from a drop down list of choices.
With date fields on Gravity Forms it generally displays the calendar below the input field. The problem occurs when that field was previously submitted by a visitor and the visitor returns to resubmit that form. The autocomplete drop down list will cover the drop down calendar making it difficult to select a date.
We may have a solution. Try using the snippet within this article to turn off the autocomplete feature on:
- the entire form
- a specific form
- a specific form field
Keep in mind that this snippet may not work on all browsers and they constantly revise how they handle such fields.
Disable Autocomplete on Gravity Forms
To utilize this snippet to disable autofill on your form add the following code to your functions.php
file within the currently active theme or child-theme (preferred – Need a child theme? We can help.)
Notice the second “add_filter” which passes 'gform_field_content_#_#'
this is where we tell the function what to apply itself to.
- To disable autocomplete on all Gravity Forms forms on your website, replace the entire parameter with
'gform_field_content'
- To disable autocomplete on a specific form, replace the parameter with
'gform_field_content_#'
, where # is the ID of your form. - To disable autocomplete on a specific field within a specific form, replace the parameter with
'gform_field_content_#_#'
, where the first # is the ID of your form and the second # is the field ID.
/*
** Gravity Forms - Disable Autocomplete
*/
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;
}
We hope this article has helped you and your website visitors resolve any browser autocomplete issues. If this was helpful, please like us on Facebook, share this on your social media or kindly buy us a simple cup of coffee below.