Jump to content

Capturing Drop Down List Values


kcwebz

Recommended Posts

I have created this form.

 

I am trying to capture the values of the drop down lists but am having a hard time trying to do so, and was hoping someone here might be able to help me.

 

They are being declared using a unique identifier of their respective tables from my sql db. each section of product in that form has its own table and own table id which the drop down lists are using. They are declared in the form like this.

 

 

 

echo "<td><select name=". $row['goosedown_id'] .">
               <option value=''> 0 </option>
               <option>1</option>
               <option>2</option>
               <option>3</option>
               <option>4</option>
               <option>5</option>
               <option>6</option>
               <option>7</option>
               <option>8</option>
           </select>
       </td>";

 

Once the user hits submit I then try to capture these drop down lists in my orderform.php like so (this is also where I am having trouble)

 

 

$goosedown_id = ($_POST[$row['goosedown_id']]);
//..


/*-------------------First Email--------------------*/

/* Set Email for Redgraves, so they can for-full the order form */
$message = "Your contact form has been submitted by:

Order number : $random

Name: $yourname
E-mail: $email
Phone Number: $phonenumber
Mobile Number: $mobilenumber
Delivery Address : $deliveryaddress

Order:
-----------------------------------------------------------------

test goosedown_id: $goosedown_id

"foreach  ($_POST[$row['goosedown_id']] != 0) {
  "test goosedown_id: $goosedown_id"
  }"

-----------------------------------------------------------------



Comments:
$comments



End of message
";

/* Send the message using mail() function */
mail($myemail, "Order Submitted", $message);

 

As you can see I have made a minor attempt at getting the drop down lists values that are not equal to 0.. but this code is defiantly not working.. but hopefully it serves a purpose to show you waht I am trying to achieve.. any help would be greatly appreciated.. been stuck on this problem all weekend. :P

Link to comment
https://forums.phpfreaks.com/topic/269181-capturing-drop-down-list-values/
Share on other sites

It should be as simple as adding the array name in the name atribute of your select fields. Then each key will be the value of $row['goosedown_id']

 

echo "<select name=\"array_name_goes_here[{$row['goosedown_id']}]\">\n";

 

followed by your <option></option> tag sets, etc. Repeat for each select field, then

 

echo '<pre>';
print_r($_POST);
echo '</pre>';

 

to see the structure of the data. You should be easily able to loop over it once you see the structure.

If you haven't done so already, you might want to read the PHP manual. If you start on the chapter I linked you to, and at least read everything up to the chapter about Classes, it should explain most of the things you'll need with PHP.

The "Function Reference" chapter is also very useful, but that's more of a "when needed" basis. Though, if you want to read through it all, then all the more power to you. :)

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.