|
Posted by Rami Elomaa on 05/17/07 21:20
Good Man kirjoitti:
> Mike P2 <sumguyovrthar@gmail.com> wrote in news:1179433389.464406.302460
> @q75g2000hsh.googlegroups.com:
>
>> I used to use arrays in input data that will be turned into a
>> superglobal more often, but now that I care more about xHTML validity,
>> I don't. Validation checking websites (particularly the W3C validator)
>> yell at me for having square brackets in a name or id attribute. I
>> started going the simple way of just separating what would be the
>> array name from what would be the subscript with an underscore and
>> parsing that out with PHP later. Is there a better, valid way of doing
>> this that will have PHP set up my multidimensional superglobals for me
>> as it would with the square brackets?
>>
>> -Mike PII
>>
>>
>
> Hi Mike
>
> i think square brackets for the 'name' attribute is fully valid xhtml -
> you just can't have the ID with square brackets.
>
> My code for forms tends to look like:
> <input type="checkbox" value="yep" name="myBox[1]" id="myBox1" /> box 1
> <input type="checkbox" value="yep" name="myBox[2]" id="myBox2" /> box 2
Yeah, I do this always, except that I use underscore to separate index
from id, so I have name="mybox[1]" id="mybox_1", that's a valid
muthafucking code... It's in the html 4.01 spec on which xhtml is based
if you just have the patience to read it plus understand it. I once
tried but it was so technical I had to ask someone to explain it to me.
Let's see... First dig up the good old html4.01 spec, everyone has read
this at least twice, right? No, maybe it's time....
http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.4
Here is a list of input elements attributes, there's name. And it's said
to be of type CDATA. plus there are %coreattrs, in which id just happens
to belong. id is of type ID. Now here's the difference, because CDATA
and ID are defined differently.
(here http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-id
and here
http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-cdata)
"CDATA is a sequence of characters from the document character set and
may include character entities" now this is very loose definition and
does allow square brackets, but:
"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".")." id doesn't.
And mind you, while this is the html 4.01 spec, xhtml 1.0 implements
this as is, there are no changes concerning these when upgrading to xhtml.
And one more reminder, id and name are not the same thing (even though
f***ing IE used to think that they are, using names as id's when id's
were not set, allowing millions of developers to write tons of bad code)
and they need not to have the same value. id is for client, name is for
server. client uses id with scripts and css, server uses name when
proessing the data.
--
Rami.Elomaa@gmail.com
"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
[Back to original message]
|