2013-08-20 41 views
-2

我有這個PHP聯繫表格腳本(如下圖所示),我以前使用過,所以我知道的作品,但是,由於我已經隱藏了一個新的jQuery動力div : (<div class="toggle hidemail" id="drop-button" href=""> Email us here </div> <div class="hidden hiddenform">) 上下切換,我似乎根本無法發送表單,發送時的表單應該淡出,然後給用戶一個確認消息(如腳本中所示),但它不會做任何事情,我不認爲有人會知道這裏出了什麼問題,所以我可以再次獲得這個表格的工作?聯繫表格腳本不發送表格

<?php 

    $to = '[email protected]'; 
    $subject = 'Company Name'; 

    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $message = $_POST['message']; 

    $body = <<<EMAIL 
     Hello my name is $name. 
     $message 
     From $name 
     my email address is $email 

    EMAIL; 

    if($name == '' || $email == '' || $message == "") { 
     echo "<h5>Sorry, I think you missed bit....</h5>"; 
     $error = true; 
    } else { 
     $error = false; 
     mail("[email protected]", $name, $email, $message); 
     echo "<h5>Thank you for getting in touch. I'll get back to you ASAP.</h5>"; 
    } 

    if($error == true): 
?> 

<article id="contact-form">    
    <article id="load_area"> 
     <form id="my-form">      
      <input type="text" name="name" placeholder="Name" /> 
      <input type="text" name="email" placeholder="Email" /> 
      <textarea name="message" placeholder="Message" /></textarea> 
      <input type="button" class="submit_button" value="Send" name="send_button" />       
     </form>  
    </article>        
</article> 
<?php 
    endif; 
?> 

下面是HTML:

<div class="toggle hidemail" id="drop-button" href=""> Email us here </div> 
    <div class="hidden hiddenform"> 
     <article id="contact-form"> 
      <article id="load_area"> 
       <form id="my-form">   
        <input type="text" name="name" placeholder="Name" /> 
        <input type="text" name="email" placeholder="Email" /> 
        <textarea name="message" placeholder="Message" /></textarea> 
        <input type="button" class="submit_button" value="Send" name="send_button" />     
       </form> 
      </article>   
     </article> 
    </div> 

$(document).ready(function() { 
    $(".submit_button").live("click", function() { 
     $("#load_area").fadeOut('slow', function() { 
      $("#load_area").fadeIn(); 
      $.post("process.php", $("#my-form").serialize(), function(data) { 
       $("#load_area").html(data); 
      }) 
     }); 
    }) 
}) 
+0

你有沒有提交按鈕。你有JavaScript監控send_button? – Anigel

+0

這可能有點愚蠢,但請確保您輸入格式正確的地址到電子郵件字段。一些開發人員只需輸入一個隨機asdafasd值。然後SMTP服務器可能會拒絕它。 –

+0

是的,當用戶按下最後一個輸入(.submit_button)時,表單被髮送。謝謝 – spamy

回答

2

嘗試使用

$(".submit_button").on("click", function(){ 

,而不是'$(".submit_button").live("click", function(){

從jQuery的文檔:

在jQuery 1.7中,.live()方法已過時

也嘗試使用

$('#my-form').submit(function() { 
    alert('Handler for .submit() called.'); 
    return false; 
}); 

,並在您的HTML表單,像這樣設置一個動作:

<form id="my-form" action="process.php"> 
+0

謝謝!它非常完美!謝謝!!! – spamy

+0

你爲什麼不接受答案?它不適合你嗎? –