Re: Passing arrays
| From: | aaron lake | Date: | Thu, 08 May 2003 23:33:14 +0000 |
| Subject: | Re: Passing arrays | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-19817@lists.php.net to get a copy of this message | ||
You must serialize arrays when posting form data.
http://www.php.net/serialize
Don't forget you must 'unserialize' this data to use on next page.....
"Metin Kale" <m-kale@northwestern.edu> wrote in message
news:5.1.0.14.2.20030505163756.03732458@merle.it.northwestern.edu...
> Hello all..
>
> I have a web form that requires users to check a checkbox next to Things
To Do.
>
> Example:
>
> [] Ski
> [] Bike
> [] Read
>
> etc.
>
> The <input> for these is:
>
> <input type=\"checkbox\" name=\"mychoices[]\"
> value=\"ski\"> Ski
> <input type=\"checkbox\" name=\"mychoices[]\"
> value=\"bike\"> Bike
> <input type=\"checkbox\" name=\"mychoices[]\"
> value=\"read\"> Read
>
> When I submit the form, an array called $mychoices is created. Up until
> that point, everything works. I do a foreach() such as:
>
> foreach ($mychoices as $m)
> {
> echo "$m<br>";
> }
>
> This displays the content of the array fine. What I want to do is display
> this array so that the user can review what he/she entered (such as above)
> and then click a submit button to actually send the data to a form that
> would enter the data into the database. The problem I'm having is sending
> the same array through another submit. The code I have for the second
form is:
>
> echo "
> <form method=\"post\" action=\"submitchoices.php\">
> <input type=\"hidden\" name=\"mychoices\"
> value=\"$mychoices\">
> <input type=\"submit\" value=\"submit\">
> </form>
> ";
>
> I get the following result:
>
> Warning: Invalid argument supplied for foreach() in
> e:\web\htdocs\maindesk\admin\deleteatt1.php on line 6
>
> I can understand why I get this error because it's not sent as an array
> (name=\"mychoices\" and not name=\"mychoices[]\"). But when I do add the
> [] at the end of mychoices, it just ignores the array.
>
> I tried to be as clear as possible.. hopefully someone can help me. I
> think I could just recreate a new array while doing the foreach, but I'm
> wondering if there is a simpler way.
>
> Thanks,
> Metin Kale