Re: Array as hidden input
| From: | Hellekin O. Wolf | Date: | Thu, 28 Sep 2000 16:54:12 +0000 |
| Subject: | Re: Array as hidden input | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3142@lists.php.net to get a copy of this message | ||
Mirko Nalesso wrote:
>
> Hi,
> I've a problem. Can an input hidden in a form be an array? Example:
>
> File prova.php
>
> <?
> $arr=array();
> $arr[1]=11;
> $arr[2]=12;
> $arr[3]=13;
> ?>
> <form method="post" method="prova1.php">
> <? echo "<input type=\"hidden\" name=\"arr\"
> value=\"$arr\">"; ?>
> <input type=submit value="NEXT" >
> <form>
>
> File prova1.php:
>
> <?
> echo"$arr[1] - $arr[2] - $arr[3]";
> ?>
>
> On the Netscape, file prova1.php appears:
>
> r - r - a
>
> What's wrong?
>
> Mirko.
>
*** Hello,
It seems that the value passed is the string "arr"...
$arr[0] = a;
$arr[1] = r;
$arr[2] = r;
$arr[3] = a;
...
You should print an hidden entry for each value of $arr :
while (list(,$v) = each($arr))
echo "<input type=\"hidden\" name=\"arr[]\"
value=\"$v\">\n";
OR, maybe it's just that you didn't put '[]' in your input tag :
<? echo "<input type=\"hidden\" name=\"arr[]\"
value=\"$arr\">"; ?>
hellekin