Link to home
Start Free TrialLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

Change attribute $name to utilize $id instead in form

Just wondering how to replace the $name attribute of all the form fields to utilize the $id attribute instead.

These are older bugs dating back to 2004: http://pear.php.net/bugs/bug.php?id=925.

In this report it states to use $form->removeAttribute('name')

But this will remove the name attribute for the form tag only and does not remove ALL the $name attribute for the form's input fields.

Any help is appreciated. =)
ASKER CERTIFIED SOLUTION
Avatar of Rurne
Rurne
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Victor Kimura

ASKER

Hi Rurne,

Thanks for the quesitons. I'm trying to get my form (it's not online yet as I'm working locally) to be XHTML STRICT compliant with W3C. The name attribute of the form fields I believe are not XHTML compliant.

I'm currently using QuickForm rather than QuickForm2 for two reasons: 1) I couldn't find any tutorials on the implementation of the QuickForm2 and some good examples; 2) I'll now have to refactor the code to work with QuickForm2.

I'll have to eventually refactor the code to QuickForm2 but for now it seems to work well. I know if I remove the name attribute I have to refactor some Javascript then too.

Question:
Is there an easier way to make the code XHTML STRICT compliant?

Much thanks. =)

According to http://www.w3.org/TR/xhtml1/:

"4.10. The elements with 'id' and 'name' attributes

HTML 4 defined the name attribute for the elements a, applet, form, frame, iframe, img, and map....

Note that in XHTML 1.0, the name attribute of these elements is formally deprecated, and will be removed in a subsequent version of XHTML."


If you look at the DTD, you'll see that these elements have had their name attribute changed from CDATA to NMTOKEN to reflect this deprecation; however, on line 722 of the DTD, there's a comment that "the name attribute is required for all but submit & reset".  Following that is the DTD definition for inputs, and name is of type CDATA.


So, long story short, you only need to worry about removing "name" from `a`, `applet`, `form`, `frame`, `img` and `map`.  Recursion over a form's input elements is not necessary, and in fact breaks strict compliance.