Home / Admin / How to Disable Browser Autocomplete for Form Fields – specific fields
Duplicate Snippet

Embed Snippet on Your Site

How to Disable Browser Autocomplete for Form Fields – specific fields

<10
Code Preview
php
<?php
/**
 * Disable autocomplete for a specific form and field ID
 *
 * @link   https://wpforms.com/developers/disable-browser-autocomplete-for-form-fields/
 */
 
function wpf_disable_email_autocomplete( $properties, $field, $form_data ) {
     
    // This check will only disable autocomplete for Field #3 inside Form #11.
    // Removing this check would disable autocomplete on ALL fields.
    if ( absint( $form_data[ 'id' ] ) !== 11 && absint( $field[ 'id' ] ) !== 3 ) {
        return $properties;
    }
 
    $properties[ 'inputs' ][ 'primary' ][ 'attr' ][ 'autocomplete' ] = 'off';
 
    return $properties;
}
 
add_filter( 'wpforms_field_properties_email', 'wpf_disable_email_autocomplete', 10, 3 );

Comments

Add a Comment