note 40754 added to faq.html
| From: | KennWhitekennwhite dot nospam at hotmail dot com | Date: | Sat, 13 Mar 2004 13:18:25 +0000 |
| Subject: | note 40754 added to faq.html | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-66763@lists.php.net to get a copy of this message | ||
Concerning XHTML Strict and array notation in forms, hopefully the information below will be useful:
If I have a form, name="f", and, say, an input text box,
name="user_data[Password]", then in Javascript, to reference it I would do something like:
var foo = f['user_data[Password]'].value;
Now, say that in making the switch to XHTML strict, I decide to fully embrace standards compliance,
and change my form to id="f", and the input text box to id="user_data[Password]"
Because these have id instead of name, I discover, that all my javascript validation routines just
broke. It seems that I have to now change all my js code to something like:
document.getElementById( 'user_data[Password]' ).focus();
I test this on all the major modern browsers, and it works well. I'm thinking, Great! Until I
try to validate said page. It turns out that the bracket characters are invalid in id attributes.
Ack! So I read this thread:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=
UTF-8&th=78dea36fd65d9bbe&seekm=
pqx99.19%24006.13377%40news.ca.inter.net#link11
(link needs to be spliced, sorry)
What does this mean, I start asking myself? Do I have to abandon my goal to migrate to XHTML
strict? Transitional seems so unsatisfying. And why bother with a technique that seems to work on
most browsers, if it's broken. Alas, there is hope.
But then I read http://www.w3.org/TR/xhtml1/#h-4.10 carefully. It
says "name" is deprecated as a form attribute, but *NOT* specifically as an attribute in
form *elements*. It seems my solution is to use "id" for the form itself, but I can
legally use "name" for the individual form components, such as select and text input
boxes. I get the impression that "name" as an attribute is eventually going away
completely, but in extensive testing using the W3C validator, it passes "name" on form
components, as long as "id" (or, strangely, nothing) is used to denote the form itself.
So for XHTML strict, the bottom line:
1. form, use id, not name
2. input, use id if you can, but if you need to use bracketed notation (for example, passing PHP
arrays), i.e., foo[], you *MUST* use name for XHTML strict validation.
-kenn
kennwhite.nospam@hotmail.com
----
Manual Page -- http://www.php.net/manual/en/faq.html.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40754
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40754&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40754&report=yes
Search -- http://master.php.net/manage/user-notes.php