?
Solved

Change attribute $name to utilize $id instead in form

Posted on 2008-06-11
3
Medium Priority
?
271 Views
Last Modified: 2008-06-17
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. =)
0
Comment
Question by:Victor Kimura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Rurne earned 500 total points
ID: 21761905
HTML_QuickForm is deprecated.  Are you using QuickForm or QuickForm2?

removeAttribute is inherited from the HTML_Common package and should not be relied upon for XHTML compliance.  It is also deprecated in favor of HTML_Common2.

In any case, this is the expected behavior.  Examine the code at:
http://pear.php.net/package/HTML_Common/docs/latest/__filesource/fsource_HTML_Common__HTML_Common-1.2.4Common.php.html

Why, exactly, do you want to remove the name attribute from all elements in the form?  Especially when dealing with array-based checkboxes and radio buttons, this can lead to unexpected results.  What exactly are you trying to attempt?
0
 

Author Comment

by:Victor Kimura
ID: 21766148
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. =)

0
 
LVL 9

Expert Comment

by:Rurne
ID: 21771128
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.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question