473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Passing arrays through posts, gets, and cookies

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
4 2091
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pete | last post by:
Any ideas on how I can set some data in 1.asp, then have 1.asp do a server.transfer (or .execute, come to that) to 2.asp, and have 2.asp access the original data? I'm aware that the Session...
2
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
2
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: Fizzics | last post by:
This is my first post here at Bytes. I have been trolling it, mostly with the help of Google searches, for some time now. I have done about all of the searching and reading that I really know how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.