Php form with checkboxes

December 20, 2010 at 08:18:56
Specs: Macintosh
I have a form but don't know how to add multiple checkboxes. The checkboxes will be used by the person filling out the form to get their different interest. For example, baseball, football, basketball. They could check more then one box.

<body>

<?php
if ($_POST["email"]<>'') {
$ToEmail = 'myemail@domainname.com';
$EmailSubject = 'Test Form ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."
";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."
";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."
";



?>
Your message was sent
<?php
} else {
?>
<form action="test.php" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
<?php
};
?>

</body>


See More: Php form with checkboxes

Report •


#1
December 20, 2010 at 13:49:55
You will find W3 Schools to be very helpful, see their page on HTML forms
http://www.w3schools.com/html/html_...

More specifically, this example
<form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car
</form>

You can call the data from it with PHP just like the email or name fields you already have.


Report •
Related Solutions


Ask Question