Home / Admin / Changing the Name Attribute of a Hidden Field
Duplicate Snippet

Embed Snippet on Your Site

Changing the Name Attribute of a Hidden Field

This code snippet can be used to change the Name attribute of a Hidden field.

<10
Code Preview
php
<?php
/**
 * Custom function to change the name attribute of hidden fields in any form.
 *
 * @link   https://wpforms.com/developers/how-to-change-the-name-attribute-of-a-hidden-field/
 */
function wpf_field_properties_hidden( $properties, $field, $form_data ) {
  
    // Optional, you can limit to specific forms. Below, we restrict output to only the form #1000.
    if ( absint( $form_data[ 'id' ] ) !== 1000 ) {
        return;
    }
 
    // Look for the name attribute and set the name attribute to custom_name_hidden_field
    $properties[ 'inputs' ][ 'primary' ][ 'attr' ][ 'name' ] = 'custom_name_hidden_field';
    return $properties;
}
add_filter( 'wpforms_field_properties_hidden', 'wpf_field_properties_hidden', 10, 3 );

Comments

Add a Comment