Forum Moderators: coopster

Message Too Old, No Replies

checkboxes and php

please help me sort this out

         

oneofmany

9:07 pm on Jul 29, 2006 (gmt 0)

10+ Year Member



Hi. I am new to php and am working on a registration page for national school fairs. I want the user to be able to check a box in front of each fair he/she would like to attend and then proceed to providing us with registration details. Once complete, I want a reply sent to the client to thank them and indicate that his/her form was submitted. I also want the information submitted to be e-mailed to a particular address. (The information is not being submitted to a database)
My form is working just fine for the submission of client details but is not working AT ALL for the checkboxes. The following is the code of the pages (the html registration page first, the php second) Thank you for whatever assistance you provide me with!

<form id="CCregistration" name="CCregistration" method="post" action="sendRegistration.php">
<div align="left">
<table border="0" cellspacing="2">
<caption align="top">
Fall 2006 Schedule
</caption>
<tr>
<td>I will Attend </td>
<td>Location</td>
<td>Site</td>
<td>Date</td>
<td>Time</td>
</tr>
<tr>
<td><input name="CCfair[]" type="checkbox" id="checkbox_CC/NoNJ" value="CC_NorthernNJ" /></td>
<td>Northern NJ </td>
<td>NJ City University<br />
(Main Gym) <br />
Jersey City, NJ </td>
<td>Mon. Oct. 24, 2006 </td>
<td>9:30 a.m.-12:30 p.m.</td>
</tr>
<tr>
<td><input name="CCfair[]" type="checkbox" id="checkbox_CC/CentralNJ" value="CC_CentralNJ" /></td>
<td>Central NJ </td>
<td><p>Bishop Ahr HS<br />
(Main Gym)<br />
Edision, NJ
</p>
</td>
<td>Tues. Oct. 25, 2006 </td>
<td>9:30 a.m.-12:30 p.m.</td>
</tr>
<tr>
<td><input name="CCfair[]" type="checkbox" id="checkbox_CC/SoNJ" value="CC_SouthernNJ" /></td>
<td>Southern NJ </td>
<td><p>Salem Community College<br />
(Main Gym)<br />
Carneys Point, NJ </p>
</td>
<td>&nbsp;</td>
<td>9:30 a.m.-12:30 p.m.</td>
</tr>
<tr>
<td><input name="CCfair[]" type="checkbox" id="checkbox_CC/CapeAtlantic" value="CC_CapeAtlantic" /></td>
<td>CapeAtlantic</td>
<td><p>Mainland Regional HS<br />
(Main Gym)<br />
Linwood NJ
</p>
</td>
<td>&nbsp;</td>
<td>9:30 a.m.-12:30 p.m.</td>
</tr>
</table>
<p>&nbsp;</p>
<p>Institution Name:
<input name="InstitutionName" type="text" id="InstitutionName" />
<br />
Address:
<input name="Address" type="text" id="Address" />
<br />
City:
<input name="City" type="text" id="City" />
State:
<input name="State" type="text" id="State" size="2" maxlength="2" />
Zip Code:
<input name="Zip" type="text" id="Zip" size="5" maxlength="5" />
<br />
Registrant Name:
<input name="Registrant" type="text" id="Registrant" />
<br />
Title:
<input name="Title" type="text" id="Title" />
<br />
Telephone:
<input name="Telephone" type="text" id="Telephone" size="12" maxlength="12" />
Fax:
<input name="Fax" type="text" id="Fax" size="12" maxlength="12" />
<br />
Email:
<input name="Email" type="text" id="Email" />
<br />
<input type="submit" name="Submit" value="Send" />
<br />
</p>
</div>
</form>

______________________________________________________________________________________
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
echo "<p>Thank you,$_POST[Registrant],for your registration!</p><p>You will receive confirmation of your registration details in the mail.";
echo "<p>Your Institution's Name is: $_POST[InstitutionName]</p>";
$msg = "InstitutionName: $_POST[InstitutionName]\n";
$msg .= "Address: $_POST[Address]\n";
$msg .= "City: $_POST[City]\n";
$msg .= "State: $_POST[State]\n";
$msg .= "Zip: $_POST[Zip]\n";
$msg .= "Registrant : $_POST[Registrant]\n";
$msg .= "Title: $_POST[Title]\n";
$msg .= "Telephone: $_POST[Telephone]\n";
$msg .= "Fax: $_POST[Fax]\n";
$msg .= "Email: $_POST[Email]\n";
$msg .= "CCfair: $HTTP_POST_VARS[CCfair]\n";
$recipient = "whomitneedstogoto@wherethatoneis.com";
$subject = "form submission results";
$mailheaders = "from: $_POST[Registrant]\n";
$mailheaders = "Reply-to: $_POST[Email]\n";
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>

supermoi

9:16 pm on Jul 29, 2006 (gmt 0)

10+ Year Member



When a checkbox is unchecked, it is not submitted, thus you can't access it using _GET or _POST. If you want to check if it was submitted, use isset().

Also, the way you setup your checkboxes (using the brackets) means that the variable will be returned as an array, in which you should have the values of the checkboxes that were checked. Your script has to be coherent with that. Or if you want only one single button to be checked, use radio buttons instead of checkboxes.

eelixduppy

2:30 am on Jul 30, 2006 (gmt 0)



Welcome to WebmasterWorld oneofmany,

Try changing this one line:


$msg .= "CCfair: $HTTP_POST_VARS[CCfair]\n";

To something like this:


$fairs = [url=http://us2.php.net/implode]implode[/url](',',$_POST['CCfair']);
$msg .= 'CCfair: '.$fairs.'\n';

Best of luck!

oneofmany

7:33 pm on Jul 30, 2006 (gmt 0)

10+ Year Member



Thank you, eelixduppy, that code worked beautifully! I look forward to learning more about php & databases and being in the position to pass on the help!

oneofmany

7:38 pm on Jul 30, 2006 (gmt 0)

10+ Year Member



Thank you, supermoi, for that insight. I don't yet understand how the code that eelixdpuppy recommended achieved what it did, or what the difference between the approaches is, just yet (hope to soon!) but I definitely appreciate the responses.

eelixduppy

2:37 am on Jul 31, 2006 (gmt 0)




I look forward to learning more about php & databases

Here is a good place to start: Learning PHP - Books, Tutorials and Online Resources [webmasterworld.com]. Also, once you have the basics down, make sure to stop by our PHP Library [webmasterworld.com].


I don't yet understand how the code that eelixdpuppy recommended achieved what it did

Check the documentation on implode by following the link in my previous post.

Good luck ;)