j.g. Posted August 24, 2007 Share Posted August 24, 2007 Hello List! I could really use some help here...I've almost got this working, but need some answers... I have a program that allows users to select a 'New Graduate' membership, and for each one selected, they get a free tshirt. I've got that working using a 'is_new_grad' function that I created. So, if they select 2, they see 2 dropdowns to select the sizes of them. It then sends an email w/ the membership info and the shirt sizes selected. However, when the email is being sent, it's only returning the size of the LAST item selected in from the drop-downs. Example: if I sign up for four of these memberships and select four different tshirt sizes (1 Medium, 1 Lg, 1 XL, and 1 XXL), the info in the email is all XXL: New Graduate T-Shirt Size (included): XXL New Graduate T-Shirt Size (included): XXL New Graduate T-Shirt Size (included): XXL New Graduate T-Shirt Size (included): XXL Here's my code for showing the drop-down boxes: if( is_new_grad() ) //If joined as a 'New Graduate', ask for the T-Shirt size - 1 for each 'New Graduate' membership { while(list($product_id, $quantity) = each($_SESSION["cart_items"])) { for( $count = 1; $count <= $quantity; $count++) { $shirt_sizes = array("M" => "Medium (M)", "L" => "Large (L)", "XL" => "Extra Large (XL)", "XXL" => "Extra Extra Large (XXL)" ); <TR BGCOLOR=#CCCCCC> <TD CLASS="bodytext"><FONT COLOR=#961039>Select T-Shirt Size (included):</font></TD> <TD> </TD> <TD COLSPAN=5 ALIGN=RIGHT> <SELECT NAME="tsize"> <OPTION VALUE="">--Select--</OPTION> foreach( $shirt_sizes as $key => $value ) { echo "<OPTION VALUE='".$key."' "; if( $tsize == $key ) { echo " SELECTED "; } echo " >".$value."</OPTION>\n"; } </SELECT> </TD> </TR> } //end of for loop }//end of while }//END if( is_new_grad() ) And here's the code for sending the email: if( is_new_grad() ) //If joined as a 'New Graduate', ask for the T-Shirt size { while(list($product_id, $quantity) = each($_SESSION["cart_items"])) { for( $count = 1; $count <= $quantity; $count++) { if( $_POST["tsize"] ) { echo "\tNew Graduate T-Shirt Size (included): ".$_POST["tsize"]."\n"; } } } } Please, any solutions and ideas for solving this would be greatly appreciated!! Thank for your time and help!! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66523-please-help-how-to-print-all-selected-items-from-dropdown/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 It is because you are named all the select objects "tsize." You need to change the name everytime it prints a new drop down. Quote Link to comment https://forums.phpfreaks.com/topic/66523-please-help-how-to-print-all-selected-items-from-dropdown/#findComment-333115 Share on other sites More sharing options...
j.g. Posted August 24, 2007 Author Share Posted August 24, 2007 Thanks for the reply. I tried making tsize an array and storing the selections in there, but am still getting the same results. Thoughts? Thanks! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66523-please-help-how-to-print-all-selected-items-from-dropdown/#findComment-333211 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 You can't return values from a form into their own array. Each one needs to have its own name. Quote Link to comment https://forums.phpfreaks.com/topic/66523-please-help-how-to-print-all-selected-items-from-dropdown/#findComment-333216 Share on other sites More sharing options...
j.g. Posted August 24, 2007 Author Share Posted August 24, 2007 Sorry to ask, but could you please provide an example of what you're describing? I'm not sure I understand -- this is all so new to me! :-\ Thanks. -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66523-please-help-how-to-print-all-selected-items-from-dropdown/#findComment-333225 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 This is what you need to change: <SELECT NAME="tsize"> It can't be "tsize" for all of the select objects. It is kind of akward to do this when you don't know how many there will be, but one way is to have a variable counter like $i increment in the while loop, then put it at the end of tsize: $i = 0; while(list($product_id, $quantity) = each($_SESSION["cart_items"])) { echo "<SELECT NAME=\"tsize" . $i . "\">"; //* $i++; } * I have no idea how it works to just write out the html tags without breaking the php block so I am changing it to an echo statement. You can leave it how you have it if you can figure out how to put a php variable in it. Probably just "echo $i". After you have that you will need to have a loop check for the existance of the variable like: $i=0; while (isset($_POST['tsize' . $i)) { echo "\tNew Graduate T-Shirt Size (included): ".$_POST["tsize" . $i]."\n"; $i++; } Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/66523-please-help-how-to-print-all-selected-items-from-dropdown/#findComment-333238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.