PHP表单适用于索引,但不适用于联系我们页面


PHP form works on index but not contact us page

我一直在用PHP开发一个非常简单的mailer表单。我在div元素中有每个问题,这个javascript显示下一个div/question(文件格式为.php)

 <script type="text/javascript">    
  function hideshow(which){     
  if (!document.getElementById)     
  return    if (which.style.display=="block")
                which.style.display="none"  
  else which.style.display="block"  }
  </script>

并且单独的代码在显示下一个元素之前验证所选择或输入的内容。

好吧,所以在索引页上一切都很好。然而,在联系我们页面上(我想在那里提供表格,因为我怀疑很多人不会填写索引页面上的弹出窗口),我遇到了一个障碍。我的脚本一直前进到最后一个问题和提交表单的按钮。然后什么都没发生。。。我可以点击按钮,但它不会提交表单。以下是应该提交表单的脚本(包含在validation.js中):

function ageValidate(){ 'use strict';
    //Verfiy that submitter is not a robot 
    var age=document.getElementById('age').value;
    if(age === ""){     // no answer, submit form
    document.getElementById('ageErr').innerHTML = 'This is to validate that you are not a robot, please enter the correct answer to the problem.';
    return false;
    }   else if (age === "5"){  // right answer
     submitForm();   return true;   }   else {  // wrong answer
    document.getElementById('ageErr').innerHTML = 'Your answer is incorrect or you did not use the numeric format. 2 is valid, but two is not valid.';      }   }
$(document).ready(function() {   $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }   }); });

function submitForm() {     if (document.getElementsByName("serviceType")[0].value === "")
        return false;   else if (document.getElementsByName("numberPhones")[0].value === "")
        return false;   else if (document.getElementsByName("zip")[0].value === "")
        return false;   else if (document.getElementsByName("email")[0].value === "")
        return false;   else if (document.getElementsByName("name")[0].value === "")
        return false;   else if (document.getElementsByName("age")[0].value === "")
        return false;   else {      document.forms["howHelp"].submit();         }

以及表单上的最后一个问题。php:

<div id="q7" style="display:none">
    <div class="how-help">
        <h2>What is eight minus three?</h2>
        <center><div>
        <input type="text" name="age" id="age" value="<?php echo $age;?>">      
        </div><br/>
        <div id="ageErr" name="ageErr" style="color: #000;  background: #41b0cc;  font-weight:700;  width: 400px;  height: auto;  margin:0px; font-size:10pt;"></div></center>
    </div>
    <!--   FOOTER  -->
      <div class="how-help-footer">
    <center>
    <input type="button" class="jump"
        value="Continue"
        onclick="ageValidate()"></form>
      </center><a href="javascript:hideshow(document.getElementById('q6')); hideshow(document.getElementById('q7'))" class="back">BACK</a><div class="private"><a href="#" class="private"> Privacy Policy</a></div>
    </div>
</div>
    <script src="validation.js" language="javascript" type="text/javascript"></script>

同样,它在索引页上运行得很好,但在联系人页上运行不好。。。我应该补充一点,所有的文件都在同一个目录中,所以指向错误的目录应该不会有任何问题。我使用

php包括"form.php"

在两个地方都有表格,我不确定这是否是问题所在,但我的表格操作是:

$_SERVER['hp_SELF'];

我应该补充一点,这是一个由非常乐于助人的人组成的令人惊叹的社区,如果没有被问到和回答的许多问题,我就不会像现在这样参与这个项目,所以感谢过去和之前所做的一切!

因为我将表单添加到一个已经有注释表单的页面中,所以两个邮件程序的ID冲突。当我回过头来想的时候真傻。我已经把两种形式分开了。