Jump to content

passing an array to a form


jnvnsn

Recommended Posts

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

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";
}

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.