Jump to content

retrieving values through $_POST


alanl1

Recommended Posts

I have a lot of dropdown boxes that I am echoing out as shown below

 

is there a way to echo out as many as the previous page contains as they are created dynamically from spreadsheets so there could be one dropdown box or many dropdown boxes

 

<?php
$secondDropbox0 = $_POST['secondDD0'];
$secondDropbox1 = $_POST['secondDD1'];
$secondDropbox2 = $_POST['secondDD2'];
$secondDropbox3 = $_POST['secondDD3'];
$secondDropbox4 = $_POST['secondDD4'];

$thirdDropbox0 = $_POST['thirdDD0'];
$initialDropbox0 = $_POST['dropdown0'];

 

 

echo "the inital dropdown box value is equal to " . $initialDropbox0; ?><br><?php
echo "the seconds first dropdown box value is equal to " . $secondDropbox0; ?><br><?php
echo "the seconds second dropdown box value is equal to " . $secondDropbox1; ?><br><?php
echo "the seconds third dropdown box value is equal to " . $secondDropbox2; ?><br><?php
echo "the seconds fourth dropdown box value is equal to " . $secondDropbox3; ?><br><?php
echo "the seconds fifth dropdown box value is equal to " . $secondDropbox4; ?><br><?php
echo "the thirds 1st dropdown box value is equal to " . $thirdDropbox0;

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/279018-retrieving-values-through-_post/
Share on other sites

Name them as an array rather than a numerical sequence. Then you can do a simple foreach loop over them.

On the previous page:

<select name="secondDD[]">
...
</select>
<select name="secondDD[]">
...
</select>
Then on the PHP processing side:

foreach ($_POST['secondDD'] as $boxIndex=>$boxValue){
    //$boxIndex is the box number: 0, 1, 2, 3 etc...
    //$boxValue is the selected option's value.
}

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.