This contact form is only sending one item from the checkbox list to my email. I'd like to have it so that everything being checked is sent to me, with the list separated by commas (Finish: Natural Oil light, Natural oil natural, ...)
I've included both the contact.html and send.php page, and am wondering if someone can help guide me in the right direction or just fix the code.
contact.html:
<form action="send.php" method="post">
<h3>Pick Your Oak:</h3>
<input type="checkbox" name="oak[]" value="Certified French Oak" id="certified-french-oak"><label for="certified-french-oak">Certified French Oak</label><br><br>
<input type="checkbox" name="oak[]" value="European Oak" id="european-oak"><label for="european-oak">European Oak</label><br><br>
<input type="checkbox" name="oak[]" value="European White Oak" id="european-white-oak"><label for="european-white-oak">European White Oak</label><br><br>
<input type="checkbox" name="oak[]" value="American Oak" id="american-oak"><label for="american-oak">American Oak</label><br><br>
<input type="checkbox" name="oak[]" value="American White Oak" id="american-white-oak"><label for="american-white-oak">American White Oak</label><br><br>
<input type="checkbox" name="oak[]" value="ThreeFourths Engineered" id="three-fourths-engineered"><label for="three-fourths-engineered">3/4" Engineered</label><br><br>
<h3>Grade?</h3>
<input type="checkbox" name="grade[]" value="Prime" id="prime"><label for="prime">Prime</label><br><br>
<input type="checkbox" name="grade[]" value="Rustic" id="rustic"><label for="rustic">Rustic</label><br><br>
<h3>Finish?</h3>
<input type="checkbox" name="finish[]" value="Natural Oil light" id="natural-oil-light"><label for="natural-oil-light">Natural Oil light</label><br><br>
<input type="checkbox" name="finish[]" value="Natural Oil natural" id="natural-oil-natural"><label for="natural-oil-natural">Natural Oil natural</label><br><br>
<input type="checkbox" name="finish[]" value="Natural Oil white" id="natural-oil-white"><label for="natural-oil-white">Natural Oil white</label><br><br>
<input type="checkbox" name="finish[]" value="Urethane Lacquer" id="urethane-lacquer"><label for="urethane-lacquer">Urethane Lacquer</label><br><br>
<input type="checkbox" name="finish[]" value="Texturing Wire Brush" id="texturing-wire-brush"><label for="texturing-wire-brush">Texturing Wire Brush</label><br><br>
<input type="checkbox" name="finish[]" value="Texturing Hand Scrape" id="texturing-hand-scrape"><label for="texturing-hand-scrape">Texturing Hand Scrape</label><br><br>
<input type="checkbox" name="finish[]" value="Texturing Antique Distress" id="texturing-antique-distress"><label for="texturing-antique-distress">Texturing Antique Distress</label><br><br>
<input type="checkbox" name="finish[]" value="Texturing Heavy Chatter Distress" id="texturing-heavy-chatter-distress"><label for="texturing-heavy-chatter-distress">Texturing Heavy Chatter Distress</label><br><br>
<input type="checkbox" name="finish[]" value="Texturing Circle Saw Marks" id="texturing-circlresaw-marks"><label for="texturing-circlresaw-marks">Texturing Circle Saw Marks</label><br><br>
<h3>Name</h3>
<input type="text" name="yourname" id="yourname" placeholder="Full Name"><br>
<input type="email" name="email" id="email" placeholder="Email"><br>
<input type="Submit" class="button solid gold small center" style="height:40px;">FINISH!</a><br>
</form>
send.php:
<?php
/* Set e-mail recipient */
$myemail = "myemail@gmail.com";
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "You did not enter your name");
$email = check_input($_POST['email']);
$oak = check_input($_POST['oak']);
$grade = check_input($_POST['grade']);
$finish = check_input($_POST['finish']);
$subject = "New Sample Request";
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("The e-mail address you entered is not valid.");
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
A sample request form has been submitted by:
Name: $yourname
E-mail: $email
Oak types: $oak
Grades: $grade
Finishes: $finish
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: sent.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
<script>
function goBack() {
window.history.back()
}
</script>
</head>
<body>
<h4>Wait, an Error has Occurred</h4>
<p>Please correct the following error:<br />
<?php echo $myError; ?></div>
<br />
<p><button onclick="goBack()">Go Back</button>
</body>
</html>
<?php
exit();
}
?>
Aucun commentaire:
Enregistrer un commentaire