checkbox array passing to email - please help
Posted: Wed Dec 03, 2008 10:40 pm
Hello there,
This is a very simple question!! - But all my hours of searching result in a thousand different answers - none of which is exactly what i need. I have found this forum super yesterday - so hoping for the same today please. !!
Many thanks in advance,
Katie
I have a simple form with checkboxes. This is an html document
I have a php file which processes form and sends to email.
The email I am getting has the checkboxes value as "array". I have found the answers online about looping and imploding etc - just can't find the code!
What is the PHP code i am to use in order for my email to just give me the values that have been checked.?
Here is the html bit:
Here is all my php code:
This is a very simple question!! - But all my hours of searching result in a thousand different answers - none of which is exactly what i need. I have found this forum super yesterday - so hoping for the same today please. !!
Many thanks in advance,
Katie
I have a simple form with checkboxes. This is an html document
I have a php file which processes form and sends to email.
The email I am getting has the checkboxes value as "array". I have found the answers online about looping and imploding etc - just can't find the code!
What is the PHP code i am to use in order for my email to just give me the values that have been checked.?
Here is the html bit:
Code: Select all
<input name="product[]" type="checkbox" id="wallart" value="Wall Art" />
Wall Art<br>
<input name="product[]" type="checkbox" id="mobile" value="Mobile" />
Mobile
<br>
<input name="product[]" type="checkbox" id="blkboard" value="Blackboard decals" />
Blk Board Decals
<br>
<input name="product[]" type="checkbox" id="screens" value="Screens" />
Screens
<br>
<input name="product[]" type="checkbox" id="letnum" value="Letnum" />
Acrylic Letters & Numbers <br>
<input name="product[]" type="checkbox" id="shapes" value="Shapes" />
Acrylic shapes</p>Code: Select all
<?php
/* Set e-mail recipient */
$myemail = "blah@blah.com";
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject = check_input($_POST['subject'], "Write a subject");
$email = check_input($_POST['email']);
$address = check_input($_POST['address']);
$product = check_input($_POST['product']);
$screens = check_input($_POST['screens']);
$how_find = check_input($_POST['how']);
$from = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your comments");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "Hello!,
Your contact form has been submitted by:
Name: $yourname
E-mail: $email
Address: $address
Which products I am interested in?
$product - THIS IS THE BIT I NEED HELP WITH PLEASE????
How did he/she find it? $how_find
Comments:
$comments
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message, "From: $from");
/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
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)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>