jnvnsn Posted June 7, 2011 Share Posted June 7, 2011 I want to pass the array into a form but it doesn't values from the array. $array ->array to be passed. <td> <form action="export.php" method="post"> <input type='hidden' name='one[]' id="one[]" value="$array"/> <input type='hidden' name='two' id="two" value="<?php echo $b; ?>"/> <input type='hidden' name='three' id="three" value="<?php echo $c; ?>"/> <input type='hidden' name='four' id="four" value="<?php echo $d; ?>"/> <input type="submit" value="CSV"> </form> </td> This is the export.php file where the array should be passed. <?php header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=csv.csv"); require("fxn.php"); $dst = $_POST["one"]; foreach ($dst as $b) { echo "$b\n"; } ?> Suggestions anyone? I am totally clueless. Link to comment https://forums.phpfreaks.com/topic/238720-passing-an-array-to-a-form/ Share on other sites More sharing options...
teynon Posted June 7, 2011 Share Posted June 7, 2011 I don't understand the reference to export.php, but: <input type='hidden' name='one[]' id="one[]" value="$array"/> Should be something like <input type='hidden' name='one[]' id="one[]" value="<?php print_r $array;?>"/> Link to comment https://forums.phpfreaks.com/topic/238720-passing-an-array-to-a-form/#findComment-1226690 Share on other sites More sharing options...
jnvnsn Posted June 7, 2011 Author Share Posted June 7, 2011 export.php is where i'll be needing the array.so i need to pass it using post method. anyways, figured it out already. i did something like this: <form action="export.php" method="post"> <?php foreach(($array) as $value){ echo "<input type='hidden' name=\"array[".$value."]\" value = \"".$value."\"/>\n"; }?> <input type='hidden' name='two' id="two" value="<?php echo $b; ?>"/> <input type='hidden' name='three' id="three" value="<?php echo $c; ?>"/> <input type='hidden' name='four' id="four" value="<?php echo $d; ?>"/> <input type="submit" value="CSV"> </form> as for the export.php, it goes something like this: $dst = $_POST["array"]; foreach ($dst as $b) { echo $b; echo "\n"; } Link to comment https://forums.phpfreaks.com/topic/238720-passing-an-array-to-a-form/#findComment-1226699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.