Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.