PHP:表单电子邮件显示某些字段,而不是其他字段?

时间:2015-07-27 17:13:35

标签: php forms

这不是我的专属领域。我正在帮助一位朋友,我一直试图通过常识和谷歌来解决这个问题,但我无法理解。

简而言之:朋友在他的网站上有一张表格。表单通过一个PHP脚本,并在有人填写时通过电子邮件将结果发送给他。它已经工作了一段时间。他最近添加了一些新字段,现在突然间,一些字段在通过表单提交时不会通过PHP脚本返回结果。

以下是表单的HTML:

db.Departements.Where(d => d.CompanyId == company.Id).Load();

这是contactengine.php:

        <div id="contact-area">

            <form method="post" action="contactengine.php">
                <table>
                    <tr>
                        <td class="left"><label for="Name">Full Name:</label></td>
                        <td><input type="text" name="Name" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="EMT">EMT #:</label></td>
                        <td><input type="text" name="EMT" /></td>
                    </tr>

                    <tr>
                        <td class="left"><label for="NREMT">NREMT #:</label></td>
                        <td><input type="text" name="NREMT" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="Email">Email:</label></td>
                        <td><input type="text" name="Email" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="Phone">Phone:</label></td>
                        <td><input type="text" name="Phone" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="Address">Full Address:</label></td>
                        <td><textarea name="Address" rows="10" cols="20"></textarea></td>
                    </tr>
                    <tr>            
                        <td class="left"><label for="Program">Program(s):</label></td>
                        <td><input type="radio" value="EMT NCCR" name="Program"/><label>EMT NCCR</label><br />
                        <input type="radio" value="Paramedic NCCR" name="Program"/><label>Paramedic NCCR</label><br />
                                    <input type="radio" value="10 hours ConEd" name="Program"/><label>10 hours ConEd</label><br />
                                    <input type="radio" value="Snowbird EMS Conference" name="Program"/><label>Snowbird EMS Conference</label><br />
                                    <input type="radio" value="AHA ACLS" name="Program"/><label>AHA ACLS</label><br />
                                    <input type="radio" value="AHA PALS" name="Program"/><label>AHA PALS</label><br />
    </tr>

                        <tr>                
                        <td class="left"><label for="nccrtraining">Desired NCCR Training:</label></td>
                        <td><input type="radio" value="Online" name="nccrtraining" /><label>Online</label><br />
                            <input type="radio" value="DVD" name="nccrtraining"/><label>DVD</label><br  />
                        <input type="radio" value="USB" name="nccrtraining"/><label>USB Thumbdrive</label></td> 
                    </tr>  
                    <tr>
                        <td class="left"><label for="Operating">Operating System:</label></td>
                        <td><input type="radio" value="Windows" name="Operating" /><label>Windows</label><br />
                            <input type="radio" value="Mac" name="Operating"/><label>Mac</label></td>

                    </tr>   
                    <tr>
                        <td class="left"><label for="emt20hournccpcoursedate">EMT 20-hour NCCP Course Date:</label></td>
                        <td>
                        <input type="radio" value="September 26th, 2015 - 12:30PM" name="emt20hournccpcoursedate" /><label>September 26th, 2015 - 12:30PM</label><br />
            <input type="radio" value="October 17th, 2015 - 12:30PM" name="emt20hournccpcoursedate" /><label>October 17th, 2015 - 12:30PM</label><br />
                        <input type="radio" value="November 14th, 2015 12:30PM" name="emt20hournccpcoursedate" /><label>November 14th, 2015 12:30PM</label><br />
                        <input type="radio" value="December 5th, 2015 8:00AM" name="emt20hournccpcoursedate" /><label>December 5th, 2015 8:00AM</label><br />
                        <input type="radio" value="December 5th, 2015 10:30AM" name="emt20hournccpcoursedate" /><label>December 5th, 2015 10:30AM</label><br />
                       <input type="radio" value="December 5th, 2015 1:00PM" name="emt20hournccpcoursedate" /><label>December 5th, 2015 1:00PM</label><br />
    </tr>
    <tr>                

</tr>   
    <tr>
                        <td class="left"><label for="paramedic30hournccpcoursedate">Paramedic 30-hour NCCP Course Date:</label></td>
                        <td>
                        <input type="radio" value="July 17th, 2015 - 8:30AM" name="paramedic30hournccpcoursedate" /><label>July 17th, 2015 - 8:30AM</label><br />
            <input type="radio" value="August 7th, 2015 - 8:30AM" name="paramedic30hournccpcoursedate" /><label>August 7th, 2015 - 8:30AM</label><br />
                        <input type="radio" value="August 28th, 2015 8:30AM" name="paramedic30hournccpcoursedate" /><label>August 27th, 2015 8:30AM</label><br />
                        <input type="radio" value="December 4th, 2015 8:30AM" name="paramedic30hournccpcoursedate" /><label>December 4th, 2015 8:30AM</label><br />
                        <input type="radio" value="January 14th, 2016 8:30AM" name="paramedic30hournccpcoursedate" /><label>January 14th, 2016 8:30AM</label><br />
                       <input type="radio" value="February 29th, 2016 8:30AM" name="paramedic30hournccpcoursedate" /><label>February 29th, 2016 8:30AM</label><br />
    </tr>
    <tr>                

</tr>                   <tr>                    

                    <td class="left"><label for="aclsinitialcoursedate">2015 ACLS Initial Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/8 & 6/10 8AM" name="aclsinitialcoursedate" /><label> 6/8 & 6/10 8AM</label><br />
             <input type="radio" value="7/6 & 7/8 8AM" name="aclsinitialcoursedate" /><label> 7/6 & 7/8 8AM</label><br />
             <input type="radio" value="8/3 & 8/5 8AM" name="aclsinitialcoursedate" /><label> 8/3 & 8/5 8AM</label><br/>
             <input type="radio" value="9/18 & 9/25 8AM" name="aclsinitialcoursedate" /><label> 9/18 & 9/25 8AM</label><br />
         <input type="radio" value="11/6 & 11/13 8AM" name="aclsinitialcoursedate" /><label> 11/6 & 11/13 8AM</label><br /> 
                    <tr>                

                    <td class="left"><label for="aclsrecertcoursedate">2015 ACLS Recert Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/15 8AM" name="aclsrecertcoursedate" /><label> 6/15 8AM</label><br />
             <input type="radio" value="7/13 8AM" name="aclsrecertcoursedate" /><label> 7/13 8AM</label><br />
             <input type="radio" value="10/2 8AM" name="aclsrecertcoursedate" /><label> 10/2 8AM</label><br/>
             <input type="radio" value="11/20 8AM" name="aclsrecertcoursedate" /><label> 11/20 8AM</label><br/>     
    </tr>
    <tr>                

            <td class="left"><label for="palsinitialcoursedate">2015 PALS Initial Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/22 & 6/24 8AM" name="palsinitialcoursedate" /><label> 6/22 & 6/24 8AM</label><br />
             <input type="radio" value="7/20 & 7/22 8AM" name="palsinitialcoursedate" /><label> 7/20 & 7/22 8AM</label><br />
             <input type="radio" value="8/10 & 8/12 8AM" name="palsinitialcoursedate" /><label> 8/10 & 8/12 8AM</label><br/>
    <input type="radio" value="10/9 & 10/16 8AM" name="palsinitialcoursedate" /><label> 10/9 & 10/16 8AM</label><br/>        
                    <tr>                    

                    <td class="left"><label for="palsrecertcoursedate">2015 PALS Recert Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/29 8AM" name="palsrecertcoursedate" /><label> 6/29 8AM</label><br />
             <input type="radio" value="7/27 8AM" name="palsrecertcoursedate" /><label> 7/27 8AM</label><br />
             <input type="radio" value="10/23 8AM" name="palsrecertcoursedate" /><label> 10/23 8AM</label><br/>
             </td>  

                                                    <tr>



                </table>

                <div id="captcha-area" style="margin-left: 130px;">

                <?php

                require_once('recaptchalib.php');
                $publickey = "edited out for example";
                $privatekey = "edited out for example";

                # the response from reCAPTCHA
                $resp = null;
                # the error code from reCAPTCHA, if any
                $error = null;

                # are we submitting the page?
                if ($_POST["submit"]) {
                  $resp = recaptcha_check_answer ($privatekey,
                                                  $_SERVER["REMOTE_ADDR"],
                                                  $_POST["recaptcha_challenge_field"],
                                                  $_POST["recaptcha_response_field"]);

                  if ($resp->is_valid) {
                    echo "You got it!";
                    # in a real application, you should send an email, create an account, etc
                  } else {
                    # set the error code so that we can display it. You could also use
                    # die ("reCAPTCHA failed"), but using the error message is
                    # more user friendly
                    $error = $resp->error;
                  }
                }
                echo recaptcha_get_html($publickey, $error);
                ?>

                </div>

                <input type="submit" name="submit" value="Submit" class="submit-button" />
            </form>

在我填写表格时,我收到以下通过电子邮件发送给我的信息:

<?php

require_once('recaptchalib.php');
$privatekey = "key removed intentionally for example";
$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 . ")");
}

$EmailFrom = "email@address.com";
$EmailTo = "email@address.com";
$Subject = "Refresher Form Submission";
$Name = Trim(stripslashes($_POST['Name'])); 
$EMT = Trim(stripslashes($_POST['EMT'])); 
$NREMT = Trim(stripslashes($_POST['NREMT'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Phone = Trim(stripslashes($_POST['Phone'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$Program = Trim(stripslashes($_POST['Program'])); 
$nccrtraining = Trim(stripslashes($_POST['NCCR Training'])); 
$Operating = Trim(stripslashes($_POST['Operating']));
$emt20hournccpcoursedate = Trim(stripslashes($_POST['EMT 20 Hour NCCP Course Date:']));  
$paramedic30hournccpcoursedate = Trim(stripslashes($_POST['Paramedic 30 Hour NCCP Course Date']));  
$aclsinitialcoursedate = Trim(stripslashes($_POST['ACLS Initial Course Date']));  
$aclsrecertcoursedate = Trim(stripslashes($_POST['ACLS Recert Course Date']));  
$palsinitialcoursedate = Trim(stripslashes($_POST['PALS Initial Course Date']));  
$palsrecertcoursedate = Trim(stripslashes($_POST['2015 PALS Recert Course Dates:']));  

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "EMT: ";
$Body .= $EMT;
$Body .= "\n";
$Body .= "NREMT: ";
$Body .= $NREMT;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Program: ";
$Body .= $Program;
$Body .= "\n";
$Body .= "NCCR Training: ";
$Body .= $nccrtraining;
$Body .= "\n";
$Body .= "Operating: ";
$Body .= $Operating;
$Body .= "\n";
$Body .= "EMT 20 Hour NCCP Course Date: ";
$Body .= $emt20hournccpcoursedate;
$Body .= "\n";
$Body .= "Paramedic 30 Hour NCCP Course Date: ";
$Body .= $paramedic30hournccpcoursedate;
$Body .= "\n";
$Body .= "ACLS Initial Course Date: ";
$Body .= $aclsinitialcoursedate;
$Body .= "\n";
$Body .= "ACLS Recert Course Date: ";
$Body .= $aclsrecertcoursedate;
$Body .= "\n";
$Body .= "PALS Initial Course Date: ";
$Body .= $palsinitialcoursedate;
$Body .= "\n";
$Body .= "2015 PALS Recert Course Dates: ";
$Body .= $palsrecertlcoursedate;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=payment.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

字段NCCR培训,EMT 20小时NCCP课程日期,护理人员30小时NCCP课程日期,ACLS初始课程日期,ACLS录取课程日期,PALS初始课程日期和2015年PALS录取课程日期完全空白。但其他领域都很好。据我所知,所有字段都以相同的方式配置。

思考?请谢谢Stackoverflow。

2 个答案:

答案 0 :(得分:3)

因为您没有定位正确的属性。您需要使用每个表单元素的name属性,例如,$_POST['NCCR Training'])是错误的,应该是$_POST['nccrtraining'])

答案 1 :(得分:0)

您缺少在收集帖子数据时添加名称,尝试更改,

$_POST['NCCR Training'] to $_POST['nccrtraining']

$_POST['EMT 20 Hour NCCP Course Date'] to $_POST['emt20hournccpcoursedate']

$_POST['Paramedic 30 Hour NCCP Course '] to _POST['paramedic30hournccpcoursedate']

$_POST['ACLS Initial Course Date'] to $_POST['aclsinitialcoursedate']

$_POST['ACLS Initial Course Date'] to $_POST['aclsrecertcoursedate']

$_POST['PALS Initial Course Date'] to $_POST['palsinitialcoursedate']