Solved

Change attribute $name to utilize $id instead in form

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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