### [How to Change the Name Attribute of a Hidden Field](https://wpforms.com/developers/how-to-change-the-name-attribute-of-a-hidden-field/)

**Published:** September 12, 2023
**Author:** Umair Majeed

**Excerpt:** This tutorial will show you how to change the name attribute of a hidden field in your forms.

**Content:**

## Introduction

Do you have a need to change the name attribute of a hidden field in your form? By default, WPForms assigns a name to each field in your form that uses a standard format such as `wpforms[fields][1]`. This allows each field in your form to remain unique to that specific field ID in your form.

For example, in this form, we added a **Hidden Field** and the default **name** assigned is `wpforms[fields][25]`.

![by default WPForms adds a generic name to each field in your form using the wpforms title as the prefix but it will include the field ID number as well](https://wpforms.com/wp-content/uploads/2023/09/wpforms-default-name-field.jpg)If you would have a need to change this name so that you can use JavaScript or CSS to target these specific fields, you can easily change this with a small PHP filter and we’ll show you how!

## Creating the Form

We’re going to begin by creating the form and adding our fields. If you need help with how to create a form, [check out this helpful documentation](https://wpforms.com/docs/creating-first-form/ "Creating Your First Form").

For this purpose of this documentation, we’re wanting to change the name on the **Hidden Field** so we’ll include adding one of these fields to our form for internal use.

![create your form and add your fields including one hidden field](https://wpforms.com/wp-content/uploads/2023/09/wpforms-change-name-field-create-form.jpg)## Adding the snippet

Now it’s time to add the snippet to your site. If you need any assistance with how and where to add snippets to your site, [please review this useful guide for further details](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

In this snippet, it will look at any **Hidden Field** inside the form **1000** and update the **name** attribute to be `custom_name_hidden_field`.

You’ll need to update this form ID to match your own, or you can remove it completely to have it applied to all of these types of fields for all your forms.

To find your form ID number, [please take a look at this article](https://wpforms.com/developers/how-to-locate-form-id-and-field-id/).

Now when you inspect the mark-up on the page, you’ll see the `name` has changed.

![](https://wpforms.com/wp-content/uploads/2023/09/wpforms-change-name-att-after.jpg)And that’s all you need to successfully change this attribute. Would you like to also change the sublabels on the **Password** field? Take a look at our tutorial on [How to Change the Password Field Sublabels](https://wpforms.com/developers/how-to-change-the-password-field-sublabels/ "How to Change the Password Field Sublabels").

## Related

Filter Reference: [wpforms\_field\_properties](https://wpforms.com/developers/wpforms_field_properties/ "Using the wpforms_field_properties filter")

## FAQ

#### Q: Can I use this for other field types?

**A:** Yes, but avoid changing the `name` attribute for required fields like Email. WPForms relies on its default structure (`wpforms[fields][{$field_id}]`) for validation and submission. Overriding this can cause errors like validation failures or `data-server-error`.

Instead, use a custom `data-*` attribute. For example:

```

function wpf_field_properties_email( $properties, $field, $form_data ) {
  
    // Optional: Limit to a specific form ID
    if ( absint( $form_data[ 'id' ] ) !== 1000) {
        return $properties;
    }

    // Add a custom data attribute instead of modifying the name
    $properties['inputs']['primary']['attr']['data-custom-name'] = 'custom_name_email_field';

    return $properties;
}
add_filter( 'wpforms_field_properties_email', 'wpf_field_properties_email', 10, 3 );
```

**Categories:** Tutorials

**Tags:** PHP

---

