Contact form-checkbox PHP coding doesnt work
I am a beginner to web page design so i would be grateful if you can explain to me what PHP coding i would need for 'Checkbox' and where to place it in the PHP coding below. I can submit the form to my email with all the headings and the filled in forms with checkbox Yes or No.
Only problem i have is that part of the check box info appear right at the top of the email message rather than the 'Name', 'Tel', 'Email' etc..Another half of the checkbox appear where it suppose to be wih double heading as shown below. I would also like to remove the <br> from the email message. Can you also tell me how to change the colour for heading so its clear.
I have marked the checkbox code in BLUE for both HTML and PHP coding below. Sorry for the long coding. Look forward to hearing from someone. Much appreciated.
Message delivered to the email address as received:
Rear ground extension: Yes
Two-storey rear extension: Yes
Two-storey side extension: No
Loft: Yes
New Build: Yes
Other: Yes
Name: Test<br>
Email: tesf@hj.cm<br>
Contact No: 87576as<br>
Address1: addy1<br>
Address2: addy2<br>
Town: town<br>
County: county<br>
Postcode: post<br>
Property Type: Cottage<br>
Property Area: None<br>
Message:<br>
test msg
My HTML coding for the form:
<div class="contactForm">
<form id="form1" name="form1" method="post" action="test2.php">
<fieldset>
<legend><strong>Personal Information</strong></legend>
<table width="690" border="0">
<tr>
<td width="340"><p>
<label for="name" class="contactLable">Name:</label>
<input name="name" type="text" id="name" tabindex="10" size="30" />
</p></td>
<td width="340"><p>
<label for="contact_number" class="contactLable">Contact No:</label>
<input name="contact_number" type="text" id="contact_number" tabindex="20" size="30" />
</p></td>
</tr>
</table>
<table width="690" border="0">
<tr>
<td><p>
<span id="sprytextfield1">
<label for="email" class="contactLable">Email:</label>
<input name="email" type="text" id="email" tabindex="30" size="30" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span> </p></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend><strong>Project Information</strong></legend>
<p><table width="690" border="0">
<tr>
<td width="340"><p>
<label for="address1" class="contactLable">Address 1:</label>
<input name="address1" type="text" id="address1" tabindex="40" size="30" />
</p></td>
<td width="340"> <p>
<label for="address2" class="contactLable">Address 2:</label>
<input name="address2" type="text" id="address2" tabindex="50" size="30" />
</p></td>
</tr>
<tr>
<td><p>
<label for="town" class="contactLable">Town:</label>
<input name="town" type="text" id="town" tabindex="60" size="30" />
</p></td>
<td><p>
<label for="county" class="contactLable">County:</label>
<input name="county" type="text" id="county" tabindex="70" size="30" />
</p></td>
</tr>
<tr>
<td><p>
<label for="postcode" class="contactLable">Post Code:</label>
<input name="postcode" type="text" id="postcode" tabindex="80" size="10" />
</p></td>
<td> </td>
</tr>
<tr>
<td><p>
<label for="propertyType" class="contactLable">Property Type:</label>
<select name="propertyType" id="propertyType" tabindex="90">
<option>Please select</option>
<option>Detached</option>
<option>Semi-Detached</option>
<option>End of Terrace</option>
<option>Mid-Terrace</option>
<option>Flat</option>
<option>Bungalow</option>
<option>Cottage</option>
<option>Other</option>
</select>
</p></td>
<td><p>
<label for="propertyArea" class="contactLable">Property Area:</label>
<select name="propertyArea" id="propertyArea" tabindex="100">
<option>Please select</option>
<option>None</option>
<option>Listed Building</option>
<option>Conservation Area</option>
</select>
</p></td>
</tr>
</table>
</p>
</fieldset><fieldset><legend><strong>Project Type</strong></legend>
<table width="690">
<tr>
<td width="338"><label>
<input name="rearExt" type="checkbox" class="contactCheckbox" id="CheckboxGroup1_0" tabindex="110" value="rearExt"/>
Rear ground extension</label></td>
<td width="340"><input name="sideExt" type="checkbox" class="contactCheckbox" id="CheckboxGroup1_1" tabindex="120" value="sideExt"/>
Side ground extension</td>
</tr>
<tr>
<td><input name="twoStoreyRear" type="checkbox" class="contactCheckbox" id="twoStoreyRear" tabindex="130" value="twoStoreyRear"/>
Two-storey rear extension</td>
<td><input name="twoStoreySide" type="checkbox" class="contactCheckbox" id="twoStoreySide" tabindex="140" value="twoStoreySide"/>
Two-storey side extension</td>
</tr>
<tr>
<td><input name="loft" type="checkbox" class="contactCheckbox" id="loft" tabindex="150" value="loft"/>
Loft conversion </td>
<td><input name="newBuild" type="checkbox" class="contactCheckbox" id="newBuild" tabindex="160" value="newBuild"/>
New build </td>
</tr>
<tr>
<td><input name="flat" type="checkbox" class="contactCheckbox" id="flat" tabindex="170" value="flat"/>
Flat conversion</td>
<td><input name="other" type="checkbox" class="contactCheckbox" id="other" tabindex="180" value="other"/>
Other conversion</td>
</tr>
</table>
</fieldset>
<fieldset><legend><strong>Message</strong></legend>
<p>
<label for="message" class="contactLable">Your Message or Comments:</label>
<textarea name="message" id="message" cols="45" rows="5" tabindex="190"></textarea>
</p>
</fieldset>
<br />
<input type="submit" name="Sumbit" id="Sumbit" value="Submit" tabindex="200" />
</form>
</div>
PHP Coding to send to my email:
<!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=UTF-8" />
<META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
$name=addslashes($_POST['name']);
$contact_number=addslashes($_POST['contact_number']);
$email=addslashes($_POST['email']);
$address1=addslashes($_POST['address1']);
$address2=addslashes($_POST['address2']);
$town=addslashes($_POST['town']);
$county=addslashes($_POST['county']);
$postcode=addslashes($_POST['postcode']);
$propertyType=addslashes($_POST['propertyType']);
$propertyArea=addslashes($_POST['propertyArea']);
$rearExt=($_POST['rearExt'])?"Rear ground extension: Yes":"Rear ground extension: No";
$sideExt=($_POST['sideExt'])?"Side ground extension: Yes":"Side ground extension: No";
$twoStoreyRear=($_POST['twoStoreyRear'])?"Two-storey rear extension: Yes":"Two-storey rear extension: No";
$twoStoreySide=($_POST['twoStoreySide'])?"Two-storey side extension: Yes":"Two-storey side extension: No";
$loft=($_POST['loft'])?"Loft: Yes":"Loft: No";
$newBuild=($_POST['newBuild'])?"New Build: Yes":"New Build: No";
$flat=($_POST['flat'])?"Flat: Yes":"Flat: No";
$other=($_POST['other'])?"Other: Yes":"Other: No";
$msg.="\n$rearExt\n$wsideExt\n$twoStoreyRear\n$twoStoreySide\n$loft\n$newBuild\n$wflat\n$other";
$message=addslashes($_POST['message']);
// you can specify which email you want your contact form to be emailed to here
$toemail = "email@hotmail.com";
$subject = "From Website Test";
$headers = "MIME-Version: 1.0\n"
."From: \"".$name."\" <".$email.">\n"
."Content-type: text/html; charset=iso-8859-1\n";
$body = "Name: ".$name."<br>\n"
."Email: ".$email."<br>\n"
."Contact No: ".$contact_number."<br>\n"
."Address1: ".$address1."<br>\n"
."Address2: ".$address2."<br>\n"
."Town: ".$town."<br>\n"
."County: ".$county."<br>\n"
."Postcode: ".$postcode."<br>\n"
."Property Type: ".$propertyType."<br>\n"
."Property Area: ".$propertyArea."<br>\n"
."Rear ground extension: ".$rearExt."<br>\n"
."Side ground extension: ".$sideExt."<br>\n"
."Two-storey rear extension: ".$twoStoreyRear."<br>\n"
."Two-storey side extension: ".$twoStoreySide."<br>\n"
."Loft conversion: ".$loft."<br>\n"
."New build: ".$newBuild."<br>\n"
."Flat: ".$flat."<br>\n"
."Other: ".$other."<br>\n"
."Message:<br>\n"
.$message;
if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
{
echo "That is not a valid email address. Please return to the"
." previous page and try again.";
exit;
}
mail($toemail, $subject, $body, $msg, $headers);
echo "Thanks for submitting your comments";
?>
</body>
</html>
