Hi,
I have a form that has radio buttons and checkboxes. When it's submitted and processed, I only get the value of the radio button and only the value of the last checkbox (plus a list of everything that hasn't been checked). How can I get only the values that have been checked/entered?
Here's the form:
<form name="premier" method="post" action="../forms/proc_pgpkg.php">
<table width="720" border="0">
<tr align="center">
<td colspan="3"><h3>Package Selection</h3>
<p>You can choose from several
options, blah, blah.</p></td>
</tr>
<tr>
<td class="right"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="right">ID No.:</td>
<td> </td>
<td><input name="ID" type="text" id="ID" size="15">
</td>
</tr>
<tr>
<td class="right">Name:</td>
<td> </td>
<td><input name="Name" type="text" id="Name" size="60"></td>
</tr>
<tr>
<td class="right">E-Mail Address:</td>
<td> </td>
<td><input name="Email" type="text" id="Email" size="60"></td>
</tr>
<tr>
<td class="right"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="right"><input type="radio" name="Autoship" value="Package_Selection"></td>
<td> </td>
<td>Below is my selection for the Autoship Package</td>
</tr>
<tr>
<td class="right"><input type="radio" name="Autoship" value="Change"></td>
<td> </td>
<td>I am changing my previous Autoship Package selection</td>
</tr>
<tr>
<td class="right"><input type="radio" name="Autoship" value="Separate_Selections"></td>
<td> </td>
<td>I would like to purchase the following package(s) separately from my
Autoship</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="3"> </td>
</tr>
<tr>
<td width="110" class="right"> <input name="Choice[]" type="checkbox" id="Choice" value="PG01">
PG01 - $38.96<br>
<input name="Qty_PG01" type="text" id="Qty_PG01" size="3">
Qty<br></td><td width="3"> </td>
<td width="593"><strong>Candles</strong><br>
Lovely Lilac, etc.</td>
</tr>
<tr bgcolor="#CCCCCC">
<td height="5" colspan="3" class="right"><img src="../images/spacer.gif" alt="Spacer" width="12" height="3"></td>
</tr>
<tr>
<td class="right"><input name="Choice[]" type="checkbox" id="Choice[]" value="PG02">
PG02 - $42.80<br>
<input name="Qty_PG02" type="text" id="Qty_PG02" size="3">
Qty<br></td><td> </td>
<td><strong>Duo Delights</strong><br>
Fragrant Floral, etc.</td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="3" class="right"><img src="../images/spacer.gif" alt="Spacer" width="12" height="3"></td>
</tr>
<tr>
<td class="right"><input name="Choice[]" type="checkbox" id="Choice[]" value="PG03">
PG03 - $52.09<br>
<input name="Qty_PG03" type="text" id="Qty_PG03" size="3">
Qty</td><td> </td>
<td><strong>Packet Assortments</strong><br>
Raspberry Fruit Dip (2), etc.</td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="3" class="right"><img src="../images/spacer.gif" alt="Spacer" width="12" height="3"></td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="3" class="right"><img src="../images/spacer.gif" alt="Spacer" width="12" height="3"></td>
</tr>
<tr>
<td class="right"><input name="Choice[]" type="checkbox" id="Choice[]" value="PG08">
PG08 - $38.77<br>
<input name="Qty_PG08" type="text" id="Qty_PG08" size="3">
Qty</td><td> </td>
<td><strong>Gift Packaging</strong><br>
Animal Print Bags, etc.</td>
</tr>
<tr>
<td colspan="3" bgcolor="#CCCCCC" class="right"><img src="../images/spacer.gif" alt="Spacer" width="12" height="3"></td>
</tr>
<tr>
<td class="right"><img src="../images/spacer.gif" width="110" height="3"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="right"> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset"></td>
</tr>
<tr>
<td class="right"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="right"> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
and here's the php page that processes the form:
<?php
$Name = trim($Name);
$Email = trim($Email);
foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key . ": " . $value;
$message .= "\n";
}
mail("me@domain.com","PG Package","$message","From: $Name <$Email>");
header ("Location: thanks_pg.php?Name=$Name");
?>
I realize in my processing page that I'm requesting all the values, but I don't know how to get just the values for what has been entered/selected by the user filling out the form (it's something I've struggled with for a long time).
For example, in the actual e-mail returned (the long version of the form above), here is what I get with options PG01 and PG04 selected with quantities. It shows only PG04, but not PG01, but it does show the quantities chosen okay, except I would like it to show only those two chosen this time, not the Qty_PG02, Qty_PG03, etc. that didn't have values.
ID: 0000
Name: kpd
Email: [email]me@domain.com[/email]
Phone: 0000
Autoship: Separate_Selections
Choice: PG04
Qty_PG01: 3
Qty_PG02:
Qty_PG03:
Qty_PG04: 2
Qty_PG05:
Qty_PG06:
Qty_PG07:
Qty_PG08:
Submit: Submit
Help, please?
Thanks,
kpd