Solved

Change attribute $name to utilize $id instead in form

Posted on 2008-06-11
3
268 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
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Rurne earned 125 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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