Jump to content

Please Help! How To Print All Selected Items From Dropdown??


j.g.

Recommended Posts

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.

Link to comment
Share on other sites

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.

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.