Forum Moderators: open

Message Too Old, No Replies

Sending an array as HTML post data

         

tbthorpe

12:41 pm on Jul 21, 2004 (gmt 0)

10+ Year Member



Is it possible to send an array through post data as a "hidden" field? And if so, can anyone explain it to me? Thanks!

BlobFisk

12:52 pm on Jul 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can send a list of values seperated by a comma (or another seperator of your choice), but it's not an array.

A hidden input field has a value which is send as a string to whatever mechanism is in place to receive it. It is there that you could convert the string into an array.

HTH

coopster

1:22 pm on Jul 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Where is the array being created? Server-side or client-side? If it is on the server-side, you may want to consider using an alternative method to maintain state of the variable, such as a session perhaps.

CritterNYC

1:42 pm on Jul 21, 2004 (gmt 0)

10+ Year Member



Is it possible to send an array through post data as a "hidden" field? And if so, can anyone explain it to me? Thanks!

As mentioned, storing this information session-side may be easier, but a comma-seperated list would be fine for just a few variables. That's the way a series of checkbox values with the same name would be passed back to you anyway. And some scripting languages make it easy to array-ize that. You can use the split function in either PHP or ASP as well.

charlier

4:01 pm on Jul 21, 2004 (gmt 0)

10+ Year Member



If your using PHP scripts on the server side you can just use the normal php notation. MyAr[1]='this' MyAr[2]='that'. PHP will automatically arrayize it for you.

You can also have hash arrays as well. I use them for all my forms for the submit action like:

input type=image name="FormAction[AClassName::AClassFunction]" IMG SRC="/images/continue.gif"

then I just split the FormAction key to determine which class to call and what function to perform.

Its nice with regular buttons as you don't have to associate the text on the button with the action.