MattB
03-17-2010, 03:50 PM
Hi Everyone,
Thanks for reading my post. I am new to PHP and wrote a script to process a simple volunteer form with checkboxes. Everything works fine if atleast one check box is checked. However, if they are all left unchecked, I get an invalid argument error. Here is the code I am using:
$to = "me@me.com";
$subject = "Volunteer Form";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email= $_POST['email'];
$comments = $_POST['comments'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$body = "First Name: $firstname\nLast Name: $lastname\nE-Mail: $email\nComments: $comments\n$check_msg";
if (empty($email) || empty($firstname)) {
header( "Location: http://www.example.com/error.html" );}
else {
mail($to, $subject, $body);
header( "Location: http://www.example.com/thankyouvolunteer.html" );
}
I really appreciate any advice anyone has. I know this is probably really simple, but it has tortured me for 3 hours.
THANKS!
Thanks for reading my post. I am new to PHP and wrote a script to process a simple volunteer form with checkboxes. Everything works fine if atleast one check box is checked. However, if they are all left unchecked, I get an invalid argument error. Here is the code I am using:
$to = "me@me.com";
$subject = "Volunteer Form";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email= $_POST['email'];
$comments = $_POST['comments'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$body = "First Name: $firstname\nLast Name: $lastname\nE-Mail: $email\nComments: $comments\n$check_msg";
if (empty($email) || empty($firstname)) {
header( "Location: http://www.example.com/error.html" );}
else {
mail($to, $subject, $body);
header( "Location: http://www.example.com/thankyouvolunteer.html" );
}
I really appreciate any advice anyone has. I know this is probably really simple, but it has tortured me for 3 hours.
THANKS!