How do I change a drupal form name attribute to something else?

821 Views Asked by At

I'm using a Drupal 6 custom form, and I want to change the form name attribute to something else. Is this possible?

For example, I have this.

<input type="text" name="field" maxlength="128" id="edit-name" value="">

I want to change it to the following.

<input type="text" data-name="field" maxlength="128" id="edit-name" value="">
1

There are 1 best solutions below

2
acrosman On

You can add the new attribute by using hook_form_alter() and adding a #data-name to the array for the field you are trying to update. I don't think you can easily remove the name attribute in Drupal 6, but I've never tried. More on the Drupal 6 Form API.

Take Note: Drupal 6 is no longer officially supported by the community. While there are some places that are offering long term support for Drupal 6, you should plan to move to Drupal 7 or 8 soon.