Php 表单未选中的框导致错误

Php 表单未选中的框导致错误,php,forms,checkbox,implode,Php,Forms,Checkbox,Implode,我不懂PHP。我正在写这张表格。当客户未选中复选框时。我收到这个错误: 警告:incompode()[function.incompode]:在第84行的/home/content/g/t/d/gtdcompaq/html/verify.php中传递的参数无效 警告:无法修改标题信息-标题已由第102行的/home/content/g/t/d/gtdcompaq/html/verify.php:84)中的/home/content/g/t/d/gtdcompaq/html/verify.php发

我不懂PHP。我正在写这张表格。当客户未选中复选框时。我收到这个错误:

警告:incompode()[function.incompode]:在第84行的/home/content/g/t/d/gtdcompaq/html/verify.php中传递的参数无效

警告:无法修改标题信息-标题已由第102行的/home/content/g/t/d/gtdcompaq/html/verify.php:84)中的/home/content/g/t/d/gtdcompaq/html/verify.php发送

否则,表单工作得很好。当复选框未选中时,是否有办法使表单不出错?多谢各位

以下是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>

名字:
姓氏:
电话号码:
电邮:
阴极射线管显示器
印刷工
计算机
荧光灯和电池
电视
其他设备
问题:
如果你有 任何问题或顾虑请写在这里。我们会在12点内回复你 小时!
以下是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));
    }  

    ?>

如果未选中任何复选框,浏览器将不会在发送到服务器的请求中包含
回收对象2
参数。如果未选择任何检查,则调用
内爆(“,”,!\u POST[“RecycleObject 2”])
与调用
内爆(“,”,null)
相同

您可以通过以下方式进行修复:

$checks = isset($_POST["recycleobject2"]) ? $_POST["recycleobject2"] : [];
替换:

$email_message .= "Recycling:" .implode(", ",$recycleobject2)."\n";
与:

if(!empty($recycleobject2)) $email_message .= "Recycling:" .implode(", ",$recycleobject2)."\n";