joshi_v Posted October 31, 2006 Share Posted October 31, 2006 Hello everyone!Can you tell me how to pass an array as hidden variable? is it possible? If so please give me an example.Regards,Joshi. Quote Link to comment https://forums.phpfreaks.com/topic/25677-passing-an-array-as-hidden-variable/ Share on other sites More sharing options...
HuggieBear Posted October 31, 2006 Share Posted October 31, 2006 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25677-passing-an-array-as-hidden-variable/#findComment-117199 Share on other sites More sharing options...
joshi_v Posted October 31, 2006 Author Share Posted October 31, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/25677-passing-an-array-as-hidden-variable/#findComment-117203 Share on other sites More sharing options...
HuggieBear Posted October 31, 2006 Share Posted October 31, 2006 Oh, you need to do that the other way around...[code]<?php$array_name = array(1,2,3);$myvarstring = implode(",", $array_name);?><input type="hidden" name="test_array" value="<?=$myvarstring;?>">[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25677-passing-an-array-as-hidden-variable/#findComment-117205 Share on other sites More sharing options...
joshi_v Posted October 31, 2006 Author Share Posted October 31, 2006 So you mean we can't post an array directly as it is, right?Anyway i am going to use your suggestion.Thanks once again! Quote Link to comment https://forums.phpfreaks.com/topic/25677-passing-an-array-as-hidden-variable/#findComment-117206 Share on other sites More sharing options...
HuggieBear Posted October 31, 2006 Share Posted October 31, 2006 Not as far as I'm aware.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25677-passing-an-array-as-hidden-variable/#findComment-117208 Share on other sites More sharing options...
kenrbnsn Posted October 31, 2006 Share Posted October 31, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/25677-passing-an-array-as-hidden-variable/#findComment-117328 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.