简体   繁体   English

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

[英]PHP form works on index but not contact us page

I have been developing a pretty simple mailer form in PHP. 我一直在用PHP开发一个非常简单的邮件程序表单。 I have each of the questions in div elements and this javascript reveals the next div/question (it is in the file form.php) 我有div元素中的每个问题,这个javascript揭示了下一个div / question(它在文件form.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>

and a separate code validates what was selected or inputted before revealing the next element. 并且一个单独的代码验证在显示下一个元素之前选择或输入的内容。

Okay, so everything works just fine on the index page. 好的,所以在索引页面上一切正常。 However, on the contact us page (where I want the form available since I suspect many people will not fill out the popup on the index page) I have hit a snag. 但是,在联系我们页面(我希望表单可用,因为我怀疑很多人不会填写索引页面上的弹出窗口)我遇到了麻烦。 My script advances all the way to the final question and the button to submit the form. 我的脚本一直前进到最后一个问题和提交表单的按钮。 Then nothing happens... I can click the button but it does not submit the form. 然后没有任何反应......我可以点击按钮,但它不提交表格。 Here is the script that should submit the form (included in validation.js): 这是应该提交表单的脚本(包含在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();         }

and the last question on the form in form.php: 以及form.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>

Again, it works perfectly fine on the index page but not the contact page... I should add that all of the files are in the same directory so there should not be any issue with pointing to the wrong directory. 同样,它在索引页面上工作得很好,但在联系页面上却没有...我应该补充一点,所有文件都在同一个目录中,因此指向错误的目录应该没有任何问题。 I use 我用

php include 'form.php' php包含'form.php'

to have the form both places and I am not sure if this could be the issue, but my form action is: 有两个地方的形式,我不知道这可能是问题,但我的表格行动是:

$_SERVER['PHP_SELF']; $ _SERVER [ 'PHP_SELF'];

I should add that this is an amazing community of extremely helpful people and without the many questions asked and answered I would not be where I am with this project, so thanks for everything in the past and in advance! 我应该补充说,这是一个非常有帮助的人的一个惊人的社区,没有很多问题和回答,我不会在这个项目的地方,所以感谢过去和提前的一切!

Because I was adding the form to a page that already had a comment form on it, the IDs of the two mailers were in conflict. 因为我将表单添加到已经有评论表单的页面上,所以两个邮件程序的ID发生冲突。 Silly when I pull back and think about it. 当我退回去想想它时傻傻的。 I've separated the two forms. 我把这两种形式分开了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM