Solved

Change attribute $name to utilize $id instead in form

Posted on 2008-06-11
3
265 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now