*** EDIT ******
I HAVE GOT IT WORKING. Now I just help with one simple minor thing: How do I get the email to separate each checkbox selection with a Comma?
So instaed of:
Interested In: Hourly Sales Lead Generation B2B Sales
It should read:
Interested In: Hourly Sales Lead Generation, B2B Sales
Thanks, Nathan
I just signed up on this site hoping to get some help making my form to send the checkbox selections with the email.
I'm pretty much a noob with php stuff, but using a lynda.com I got my contact form at least working - now I just need to get the checkbox selections to send with the email.
Here is my form:
<form id="mainForm" method="post" name="contact" action="http://www.digicrest.com/sales/contactFormProcess.php">
<ul>
<li>Name<span>*</span> <br/>
<input class="form2" name="name" type="text" />
</li>
<li>Email Address<span>*</span> <br/>
<input class="form2" name="email" type="text" />
</li>
<li>Subject<span>*</span> <br/>
<input class="form2" name="subject" type="text" />
</li>
<li>Company<span>*</span> <br/>
<input class="form2" name="company" type="text" />
</li>
<li>Phone Number <br/>
<input class="form2" name="phone" type="text" />
</li>
<li id="checkboxes">
I'm Interested In:
<br />
<div><input type="checkbox" name="interested[]" value="Pay For Performance Appointment Setting" class="checkbox" id="option1" /> Pay For Performance Appointment Setting
<br />
<input type="checkbox" name="interested[]" value="Hourly Sales Lead Generation" class="checkbox" id="option2" /> Hourly Sales Lead Generation
<br />
<input type="checkbox" name="interested[]" value="B2B Sales" class="checkbox" id="option3" /> B2B Sales
<br />
<input type="checkbox" name="interested[]" value="Inbound Lead Generation" class="checkbox" id="option4" /> Inbound Lead Generation
</div>
</li>
<li><span class="clearLeft"></span></li>
<div class="clearLeft"></div>
<li>Comments / Details<span>*</span> <br/>
<textarea class="form2B" cols="20" rows="6" name="message"></textarea>
</li>
</ul>
<div id="formButtons2">
<input class="clear2" type="reset" value=""/>
<input class="submit" type="image" name="submit" src="images/send-big.jpg" alt="" />
</div>
</form>
-and here is my php-
<?php
/* Subject and Email Variables */
$emailSubject = $_POST['subject'];
$webMaster = 'info@digicrest.com';
$email = $_POST['email'];
/* Gathering Data Variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$subjectField = $_POST['subject'];
$companyField = $_POST['company'];
$phone = $_POST['phone'];
$messageField = $_POST['message'];
$interestedField = implode(' ', $_POST['interested']);
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Subject: $subjectField <br>
Company: $companyField <br>
Phone: $phone <br>
Interested In: $interestedField <br>
Message: $messageField <br>
EOD;
$headers = "From: $email
";
$headers .= "Content-type: text/html
";
$success = mail($webMaster, $emailSubject, $body, $headers);
/* Results Rendered as HTML */
$theResults = <<<EOD
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome To Sales Source Lead Generation - B2B Solutions</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="css/basic-jquery-slider.css" />
</head>
<body>
<!-- header -->
<div id="pageArea">
<div id="headerArea">
<div id="header">
<div class="content">
<a id="logo" href="index.html" title="Home"><img src="images/logo.jpg" width="198" height="102" alt=""/></a>
<div id="phone">
Call us Toll Free: <span>1-888-557-4223</span> Ext 2
</div>
<div id="navbar">
<div id="home"><a href="index.html" title="Home"></a></div>
<div> | </div>
<div id="about"><a href="about.html" title="About Us"></a></div>
<div> | </div>
<div id="services"><a href="services.html" title="Services"></a></div>
<div> | </div>
<div id="faq"><a href="faq.html" title="FAQ"></a></div>
<div> | </div>
<div id="rep"><a href="rep.html" title="Become a Rep"></a></div>
<div> | </div>
<div id="contact"><a href="contact.html" title="Contact Us"><img src="images/contact-current.jpg" width="87" height="16" alt="" /></a></div>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div id="barArea2">
<div class="content">
<div id="light"><img src="images/light.png" width="787" height="493" alt="" /></div>
<h1 class="pageTitle">Message Sent!</h1>
</div>
</div>
<div id="hr"></div>
<div class="contentArea">
<div class="content">
<div align="center">Thank you for your message! Your email will be answered as soon as possible!
<br />
<br />
<a href="index.html" title="Home">Click To Go Back!</a>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>
I appreciate any help :)
Thanks for reading.
-Nathan
In your case, your checkboxes are stored on the $_POST['interested']
array. So you need to include the imploded form of them ($interestedField
).
If you want the commas, simply implode by ", "
instead of " "
.
Assuming everything else is working:
/* Gathering Data Variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$choices = implode(", ", $_POST['interested']);
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Subject: $subjectField <br>
Email: $emailField <br>
Message: $messageField <br>
Choices: $choices
EOD;
Note that this will just give you the VALUES of the checkboxes (eg: 1, 2, 3, 4) and not the text (eg: "Pay For Performance Appointment Setting"). To get this, you'd need to have those texts somewhere in your PHP:
$labels = array("1"=>"Pay For Performance Appointment Setting",
"2"=>"Hourly Sales Lead Generation",
"3"=>"B2B Sales",
"4"=>"Inbound Lead Generation");
/* Gathering Data Variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$choices = array();
foreach($_POST['interested'] as $choice) {
$choices[] = $labels[$choice];
}
$choices = implode(", ", $choices);
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Subject: $subjectField <br>
Email: $emailField <br>
Message: $messageField <br>
Choices: $choices
EOD;
Hope this helps.
EDIT: OK, you changed your post while I was answering so that the values of the checkboxes contained the text which makes the second part of my answer redundant. If you wanted to save the data into a database, the best way would be to have numeric values, and the description stored somewhere else.