2016-04-13 37 views
1

我一直在PHP中開發一個非常簡單的郵件表單。我每次在div元素的問題,並在此javascript揭示了下一個DIV /問題(這是在文件form.php的)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();   } 

和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> 

此外,它完美罰款索引頁,但不是聯繫頁... 我應該補充說,所有的文件都在同一個目錄下,所以不應該有任何指向錯誤目錄的問題。我用

PHP的包括「form.php的」

有形式這兩個地方,我不知道這可能是問題,但我的表單操作是:

$ _SERVER ['PHP_SELF'];

我應該補充一點,這是一個非常有幫助的人的驚人社區,沒有很多問題和回答我不會在這個項目的位置,所以感謝過去和提前的一切!

+4

請確保您的index.php和contact.php頁面上都有相同的ID,因爲您對兩者都使用相同的腳本。另外請確保您的contact.php頁面上沒有任何衝突的ID。你應該在這裏包含你的'

'代碼。 –

+0

請包括整個「」。另外,請準確地包含如何將'form.php'包含爲'php include'form.php'',因爲它實際上不包含表單。 – Marcus

+0

這是我的第一篇文章,我正在弄清楚如何添加代碼,因此缺少的部分;但它在頁面上:'<?php include'form.php'?>' – Allison

回答

0

因爲我是將表單添加到已經有評論表單的頁面上,所以兩個郵件的ID是衝突的。傻了,當我拉回來想一想。我把這兩種形式分開了。