By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,491 Members | 3,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,491 IT Pros & Developers. It's quick & easy.

Passing arrays through posts, gets, and cookies

P: n/a
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

May 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mike P2 <su***********@gmail.comwrote 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

etc....

When processing the form, you can still do...

foreach($myBox as $key=>$value) {

}

....to retrieve the appropriate key/value pairs.

May 17 '07 #2

P: n/a
Mike P2 wrote:
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.
Actually, [] in a "name" (not in "id") is valid. Can you post an example
of non-validating code?

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
I'm afraid there is no way to achieve the same _automatically_.

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
May 17 '07 #3

P: n/a
Good Man kirjoitti:
Mike P2 <su***********@gmail.comwrote 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-html40...ms.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-html40...s.html#type-id
and here
http://www.w3.org/TR/1999/REC-html40...tml#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.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 17 '07 #4

P: n/a
Thanks for the suggestions. I used to think even name couldn't have
square brackets, but after reading your responses, I tried again, and
so it is ok. As was said, the id attribute is what doesn't work.

This was a while ago, so I don't remember exactly what it was that
gave me this habit. I remember I was dealing with some Dreamweaver-
generated code and it was using getElementByID() to find things based
on the name attribute or something like that, I got confused over that
and probably ended up just setting id and name to the same thing.

So name with brackets, id with an underscore. Problem solved. Thanks
to all for telling me that.

-Mike PII

May 18 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.