Jump to content

Passing an array as hidden variable


joshi_v

Recommended Posts

Do you mean you want to pass a group of values in a form as a hidden field?  If so then I'd suggest something like this in your form

[code]<input type="hidden" name="myformarray" value="This,Is,An,Array,Of,Words">[/code]

Then make your php look like this:

[code]
<?php
$myarray = explode(",", $_POST['myformarray']);

echo "<pre>\n";
var_dump($myarray);
echo "</pre>\n";
?>
[/code]

Regards
Huggie
Thanks for response!


exactly what i am tryign to do is passing an array like .

i tried it but it is showing empty array even though there are some values in the actual array i am trying to pass.

[code]$array_name=array("1","2","3");
<input type="hidden" name="test_array" value="<?=$array_name;?>">[/code]


So please  tell me how to pass this as hidden?


Regards,
Joshi.
You can also serialize the array, pass the serialized value and unserialize it when you process the form.
[code]<?php
<?php
$array_name = array(1,2,3);
$myvarstring = htmlentities(serialize($array_name),ENT_QUOTES);
?>

<input type="hidden" name="test_array" value="<? echo $myvarstring;?>">
?>[/code]

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.