Re: passing array as hidden field
| From: | Kevin Stone | Date: | Wed, 24 Apr 2002 18:09:25 +0000 |
| Subject: | Re: passing array as hidden field | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94429@lists.php.net to get a copy of this message | ||
Concept is solid, method is wrong. Understand that <name=layer[]> is but
one index in the array. To produce an array with multiple indicies you must
create a separate <input> for each value. Example..
foreach ($layer as $lay)
{
echo "<input type='hidden' name='layer[]' value=$lay>";
}
That will produce..
<input type='hidden' name='layer[]' value=a>
<input type='hidden' name='layer[]' value=b>
<input type='hidden' name='layer[]' value=c>
And when the submit button is pressed $_POST will contain the list array
$layer.
-Kevin
----- Original Message -----
From: "Pushkar Pradhan" <pushkar@ERC.MsState.Edu>
To: <php-general@lists.php.net>
Sent: Wednesday, April 24, 2002 12:02 PM
Subject: [PHP] passing array as hidden field
> I want to pass a 1 dim. array through a form, I use the hidden field and
> do as follows:
> <form method=POST ACTION=\"updateHTML.php\">
> <input type=hidden name=layer[] value=\"";
> foreach($layer as $lay) {
> print "$lay ";
> }
> print "\">
> This generates the foll. source:
> <form method=POST ACTION="updateHTML.php">
> <input type=hidden name=layer[] value="a b c d e f g h ">
>
> where actually it should be $layer[] = "a", "b", "c", ....
> i.e. it doesn't remain an array anymore and thus I cannot do array
> operations (eg. array_slice etc.) on it.
> Can anyone tell how I can pass it to my forms as an array? Thanks
>
>
> -Pushkar S. Pradhan
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>