Jump to content

retrieving values through $_POST


alanl1
Go to solution Solved by kicken,

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
Share on other sites

  • Solution

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.
}
Link to comment
Share on other sites

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.