Contact form not mailing all the data sellected in Checkbox Group of the form
Permalink
Hi. I'm very new to the designing scene and has created some sites but have some trouble with the checkbox group I have created in the form.
I used a Simple Contact form solution to get started with the code and edited it to what I needed.
I recieve the mails sent by the form but when more that 1 choice is sellected in the contact form I'm not recieving all the data sellected, onlt the last selection that was made.
Here is the code:
HTML Form:
<form action="html_form_send_1.php" method="post" enctype="multipart/form-data" name="htmlform">
<table width="960px">
<td width="330">
</tr>
<tr>
<td valign="top""><label for="name">Business Name *</label></td>
<td width="618" valign="738"><input type="text" name="name" maxlength="50" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="categories">Business Categories *</label></td>
<td valign="top">
<label>
<input type="checkbox" name="categories" value="Accommodation" id="categories_0">
Accommodation</label>
<label>
<input type="checkbox" name="categories" value="Acounting" id="categories_1">
Accounting</label>
<label>
<input type="checkbox" name="categories" value="Arts & Crafts" id="categories_2">
Arts & Crafts</label>
<label>
<input type="checkbox" name="categories" value="Attorneys" id="categories_3">
Attorneys</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Auctions" id="categories_4">
Auctions</label>
<label>
<input type="checkbox" name="categories" value="Automotive" id="categories_5">
Automotive</label>
<label>
<input type="checkbox" name="categories" value="Banking" id="categories_6">
Banking</label>
<label>
<input type="checkbox" name="categories" value="Carpenting" id="categories_7">
Carpenting</label>
<label>
<input type="checkbox" name="categories" value="Catering" id="categories_8">
Catering</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Clubs" id="categories_9">
Clubs</label>
<label>
<input type="checkbox" name="categories" value="Construction" id="categories_10">
Construction</label>
<label>
<input type="checkbox" name="categories" value="Draughting" id="categories_11">
Draughting</label>
<label>
<input type="checkbox" name="categories" value="Education" id="categories_12">
Education</label>
<label>
<input type="checkbox" name="categories" value="Electrical" id="categories_13">
Electrical</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Engineering" id="categories_14">
Engineering</label>
<label>
<input type="checkbox" name="categories" value="Entertainment" id="categories_15">
Entertainment</label>
<label>
<input type="checkbox" name="categories" value="Farming Services" id="categories_16">
Farming Services</label>
<label>
<input type="checkbox" name="categories" value="Food & Drink" id="categories_17">
Food & Drink</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Funeral Services" id="categories_18">
Funeral Services</label>
<label>
<input type="checkbox" name="categories" value="Health & Beauty" id="categories_19">
Health & Beauty</label>
<label>
<input type="checkbox" name="categories" value="Hobbies" id="categories_20">
Hobbies</label>
<label>
<input type="checkbox" name="categories" value="House & Home" id="categories_21">
House & Home</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Internet Services" id="categories_22">
Internet Services</label>
<label>
<input type="checkbox" name="categories" value="IT Solutions" id="categories_23">
IT Solutions</label>
<label>
<input type="checkbox" name="categories" value="Jewellers" id="categories_24">
Jewellers</label>
<label>
<input type="checkbox" name="categories" value="Mechinary" id="categories_25">
Mechinary</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Medical Services" id="categories_26">
Medical Services</label>
<label>
<input type="checkbox" name="categories" value="Photography" id="categories_27">
Photography</label>
<label>
<input type="checkbox" name="categories" value="Plumbing" id="categories_28">
Plumbing</label>
<label>
<input type="checkbox" name="categories" value="Property" id="categories_29">
Property</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Restorants" id="categories_30">
Restorants</label>
<label>
<input type="checkbox" name="categories" value="Retail Stores" id="categories_31">
Retail Stores</label>
<label>
<input type="checkbox" name="categories" value="Safety" id="categories_32">
Safety</label>
<label>
<input type="checkbox" name="categories" value="Scrap Yards" id="categories_33">
Scrap Yards</label>
<label>
<input type="checkbox" name="categories" value="Sports" id="categories_34">
Sports</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Transport" id="categories_35">
Transport</label>
</td>
</tr>
<tr>
<td valign="top"><label for="discription">Business Discription * </label></td>
<td valign="top"><textarea name="discription" maxlength="1000" cols="30" rows="6"></textarea>1000 Characters MAX</td>
</tr>
<tr>
<td valign="top"><label for="address">Business Address * </label></td>
<td valign="top"><textarea name="address" maxlength="1000" cols="30" rows="6"></textarea>1000 Characters MAX</td>
</tr>
<tr>
<td valign="top"><label for="town">Town *</label></td>
<td valign="top"><select name="town">
<option value="<Select Town Here>" selected><Select Town Here></option>
<option value="Bethal">Bethal</option>
<option value="Secunda">Secunda</option>
<option value="Standerton">Standerton</option>
</select>
If town is not available, <a href="links.html">CLICK HERE</a> and fill out the form...</td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input type="text" name="telephone" maxlength="30" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="cell">Cell Phone Number</label></td>
<td valign="top"><input type="text" name="cell" maxlength="30" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="fax">Fax Number</label></td>
<td valign="top"><input type="text" name="fax" maxlength="30" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input type="text" name="email" maxlength="80" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments * </label></td>
<td valign="top"><textarea name="comments" maxlength="1000" cols="30" rows="6"></textarea>1000 Characters MAX</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">By submitting this form you agree to our <a href="terms.html">Terms and Conditions</a>. Make sure you understand them.</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" name="Submit" id="Submit" value="Submit"></td>
</tr>
</table>
</form>
PHP Mailer Code:
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "banners@rfwebbanners.co.za";
$email_subject = "Banner Registration";
function died($error) {
// your error code can go here
echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['categories']) ||
!isset($_POST['discription']) ||
!isset($_POST['address']) ||
!isset($_POST['town']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['cell']) ||
!isset($_POST['fax']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$categories = $_POST['categories']; // required
$discription = $_POST['discription']; // required
$address = $_POST['address']; // required
$town = $_POST['town']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$cell = $_POST['cell']; // required
$fax = $_POST['fax']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(strlen($name) < 2) {
$error_message .= 'The Business Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Business Name: ".clean_string($name)."\n";
$email_message .= "Business Categories: ".clean_string($categories)."\n";
$email_message .= "Business Discription: ".clean_string($discription)."\n";
$email_message .= "Business Address: ".clean_string($address)."\n";
$email_message .= "Town: ".clean_string($town)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Cell Number: ".clean_string($cell)."\n";
$email_message .= "Fax Number: ".clean_string($fax)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<?php
header("refresh: 6; url= register.html"); // you can change seconds
20
?>
What should I do to fix the problem?
I used a Simple Contact form solution to get started with the code and edited it to what I needed.
I recieve the mails sent by the form but when more that 1 choice is sellected in the contact form I'm not recieving all the data sellected, onlt the last selection that was made.
Here is the code:
HTML Form:
<form action="html_form_send_1.php" method="post" enctype="multipart/form-data" name="htmlform">
<table width="960px">
<td width="330">
</tr>
<tr>
<td valign="top""><label for="name">Business Name *</label></td>
<td width="618" valign="738"><input type="text" name="name" maxlength="50" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="categories">Business Categories *</label></td>
<td valign="top">
<label>
<input type="checkbox" name="categories" value="Accommodation" id="categories_0">
Accommodation</label>
<label>
<input type="checkbox" name="categories" value="Acounting" id="categories_1">
Accounting</label>
<label>
<input type="checkbox" name="categories" value="Arts & Crafts" id="categories_2">
Arts & Crafts</label>
<label>
<input type="checkbox" name="categories" value="Attorneys" id="categories_3">
Attorneys</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Auctions" id="categories_4">
Auctions</label>
<label>
<input type="checkbox" name="categories" value="Automotive" id="categories_5">
Automotive</label>
<label>
<input type="checkbox" name="categories" value="Banking" id="categories_6">
Banking</label>
<label>
<input type="checkbox" name="categories" value="Carpenting" id="categories_7">
Carpenting</label>
<label>
<input type="checkbox" name="categories" value="Catering" id="categories_8">
Catering</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Clubs" id="categories_9">
Clubs</label>
<label>
<input type="checkbox" name="categories" value="Construction" id="categories_10">
Construction</label>
<label>
<input type="checkbox" name="categories" value="Draughting" id="categories_11">
Draughting</label>
<label>
<input type="checkbox" name="categories" value="Education" id="categories_12">
Education</label>
<label>
<input type="checkbox" name="categories" value="Electrical" id="categories_13">
Electrical</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Engineering" id="categories_14">
Engineering</label>
<label>
<input type="checkbox" name="categories" value="Entertainment" id="categories_15">
Entertainment</label>
<label>
<input type="checkbox" name="categories" value="Farming Services" id="categories_16">
Farming Services</label>
<label>
<input type="checkbox" name="categories" value="Food & Drink" id="categories_17">
Food & Drink</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Funeral Services" id="categories_18">
Funeral Services</label>
<label>
<input type="checkbox" name="categories" value="Health & Beauty" id="categories_19">
Health & Beauty</label>
<label>
<input type="checkbox" name="categories" value="Hobbies" id="categories_20">
Hobbies</label>
<label>
<input type="checkbox" name="categories" value="House & Home" id="categories_21">
House & Home</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Internet Services" id="categories_22">
Internet Services</label>
<label>
<input type="checkbox" name="categories" value="IT Solutions" id="categories_23">
IT Solutions</label>
<label>
<input type="checkbox" name="categories" value="Jewellers" id="categories_24">
Jewellers</label>
<label>
<input type="checkbox" name="categories" value="Mechinary" id="categories_25">
Mechinary</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Medical Services" id="categories_26">
Medical Services</label>
<label>
<input type="checkbox" name="categories" value="Photography" id="categories_27">
Photography</label>
<label>
<input type="checkbox" name="categories" value="Plumbing" id="categories_28">
Plumbing</label>
<label>
<input type="checkbox" name="categories" value="Property" id="categories_29">
Property</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Restorants" id="categories_30">
Restorants</label>
<label>
<input type="checkbox" name="categories" value="Retail Stores" id="categories_31">
Retail Stores</label>
<label>
<input type="checkbox" name="categories" value="Safety" id="categories_32">
Safety</label>
<label>
<input type="checkbox" name="categories" value="Scrap Yards" id="categories_33">
Scrap Yards</label>
<label>
<input type="checkbox" name="categories" value="Sports" id="categories_34">
Sports</label>
<br/>
<label>
<input type="checkbox" name="categories" value="Transport" id="categories_35">
Transport</label>
</td>
</tr>
<tr>
<td valign="top"><label for="discription">Business Discription * </label></td>
<td valign="top"><textarea name="discription" maxlength="1000" cols="30" rows="6"></textarea>1000 Characters MAX</td>
</tr>
<tr>
<td valign="top"><label for="address">Business Address * </label></td>
<td valign="top"><textarea name="address" maxlength="1000" cols="30" rows="6"></textarea>1000 Characters MAX</td>
</tr>
<tr>
<td valign="top"><label for="town">Town *</label></td>
<td valign="top"><select name="town">
<option value="<Select Town Here>" selected><Select Town Here></option>
<option value="Bethal">Bethal</option>
<option value="Secunda">Secunda</option>
<option value="Standerton">Standerton</option>
</select>
If town is not available, <a href="links.html">CLICK HERE</a> and fill out the form...</td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input type="text" name="telephone" maxlength="30" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="cell">Cell Phone Number</label></td>
<td valign="top"><input type="text" name="cell" maxlength="30" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="fax">Fax Number</label></td>
<td valign="top"><input type="text" name="fax" maxlength="30" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input type="text" name="email" maxlength="80" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments * </label></td>
<td valign="top"><textarea name="comments" maxlength="1000" cols="30" rows="6"></textarea>1000 Characters MAX</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">By submitting this form you agree to our <a href="terms.html">Terms and Conditions</a>. Make sure you understand them.</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" name="Submit" id="Submit" value="Submit"></td>
</tr>
</table>
</form>
PHP Mailer Code:
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "banners@rfwebbanners.co.za";
$email_subject = "Banner Registration";
function died($error) {
// your error code can go here
echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['categories']) ||
!isset($_POST['discription']) ||
!isset($_POST['address']) ||
!isset($_POST['town']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['cell']) ||
!isset($_POST['fax']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$categories = $_POST['categories']; // required
$discription = $_POST['discription']; // required
$address = $_POST['address']; // required
$town = $_POST['town']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$cell = $_POST['cell']; // required
$fax = $_POST['fax']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(strlen($name) < 2) {
$error_message .= 'The Business Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Business Name: ".clean_string($name)."\n";
$email_message .= "Business Categories: ".clean_string($categories)."\n";
$email_message .= "Business Discription: ".clean_string($discription)."\n";
$email_message .= "Business Address: ".clean_string($address)."\n";
$email_message .= "Town: ".clean_string($town)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Cell Number: ".clean_string($cell)."\n";
$email_message .= "Fax Number: ".clean_string($fax)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<?php
header("refresh: 6; url= register.html"); // you can change seconds
20
?>
What should I do to fix the problem?