dongpai6567 2014-08-13 18:07
浏览 33
已采纳

形成未经检查的框导致错误

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.

";

    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)."
";
    $email_message .= "Last Name: ".clean_string($last_name2)."
";
    $email_message .= "Email: ".clean_string($email_from2)."
";
    $email_message .= "Telephone: ".clean_string($telephone2)."
";
    $email_message .= "Comments: ".clean_string($comments2)."
";
    $email_message .= "Recycling:" .implode(", ",$recycleobject2)."
";




    // create email headers
    $headers = 'From: '.$email_from2."
".
    'Reply-To: '.$email_from2."
" .
    '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条回答 默认 最新

  • duanlv5084 2014-08-13 18:11
    关注

    Replace:

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

    With:

    if(!empty($recycleobject2)) $email_message .= "Recycling:" .implode(", ",$recycleobject2)."
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么