I do not know PHP. I am working on this form. When the the customer leaves the check boxes unchecked. I receive this error:
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/g/t/d/gtdcompaq/html/verify.php on line 84
Warning: Cannot modify header information - headers already sent by (output started at /home/content/g/t/d/gtdcompaq/html/verify.php:84) in /home/content/g/t/d/gtdcompaq/html/verify.php on line 102
Otherwise the form works well. Is there a way to have the form not error out when the boxes are left unchecked? Thank you
Here is the html:
<form action="verify.php" method="post" enctype="multipart/form-data" name="form" >
<label> First Name: <input name="firstname2" type="text" id="firstname2" size="30"
maxlength="40"/></label>
<label> Last Name: <input name="lastname2" type="text" id="lastname2" size="30"
maxlength="40" /></label>
<label>Phone Number:<input name="phonenumber2" type="text" id="phonenumber2" size="30"
maxlength="40" /></label>
<label>Email:<input name="email2" type="text" id="email2" size="30" maxlength="40"
/></label>
<label>CRT Monitors <input name="recycleobject2[]" type="checkbox"
value="crtmonitors"/></label>
<label>Printers <input name="recycleobject2[]" type="checkbox" value="printers"
/></label>
<label>Computers <input name="recycleobject2[]" type="checkbox" value="computers"
/></label>
<label>Fluorescent Lamps and Batteries <input name="recycleobject2[]" type="checkbox"
value="lamps" /></label>
<label>Televisions <input name="recycleobject2[]" type="checkbox" value="television"
/></label>
<label>Other Equipment <input name="recycleobject2[]" type="checkbox" value="other" />
</label>
Questions:<br />
<textarea name="comments2" id="comments2 "cols="60" rows="3" class="news">If you have
any questions or concerns please write them here. We will get back to you within 12
Hours!</textarea>
</label>
<?php
require_once('recaptchalib.php');
$publickey = "X"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<input name="Submit2" type="submit" value="Get a Quote!" />
</form>
Here is the PHP:
<?php
if(isset($_POST['Submit2'])) {
require_once('recaptchalib.php');
$privatekey = "X";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
}
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "x.com";
$email_subject = "Request a Quote";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstname2']) ||
!isset($_POST['lastname2']) ||
!isset($_POST['email2']) ||
!isset($_POST['phonenumber2'])) {
died('We are sorry, but there appears to be a problem with the form you
submitted. Please go back and make sure you filled out all required fields.
Thank you!');
}
$email_from2 = $_POST['email2'];
$first_name2 = $_POST['firstname2'];
$last_name2 = $_POST['lastname2'];
$telephone2 = $_POST['phonenumber2'];
$comments2 = $_POST['comments2'];
$recycleobject2 = $_POST['recycleobject2'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from2)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name2)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name2)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments2) < 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 .= "First Name: ".clean_string($first_name2)."\n";
$email_message .= "Last Name: ".clean_string($last_name2)."\n";
$email_message .= "Email: ".clean_string($email_from2)."\n";
$email_message .= "Telephone: ".clean_string($telephone2)."\n";
$email_message .= "Comments: ".clean_string($comments2)."\n";
$email_message .= "Recycling:" .implode(", ",$recycleobject2)."\n";
// create email headers
$headers = 'From: '.$email_from2."\r\n".
'Reply-To: '.$email_from2."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
$insertGoTo = "thankyou.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
Replace:
$email_message .= "Recycling:" .implode(", ",$recycleobject2)."\n";
With:
if(!empty($recycleobject2)) $email_message .= "Recycling:" .implode(", ",$recycleobject2)."\n";