联系表格不解析错误或成功消息

问题描述:

为项目创建一个小型联系人类型表单,人们可以在该项目中注册对该网站的兴趣,并提供关于他们自己的一些细节。所以我决定按照本教程进行修改以适应我的需求:http://bit.ly/13zQ7em联系表格不解析错误或成功消息

我已经修改了PHP和jQuery以获取要发送的电子邮件,但是现在确实如此我无法弄清为什么jQuery当它输入时不会触发成功消息,或者当我输入某些内容时显示任何错误。

据我所知,一切都应该通过OK开火,但我明显错过了某些东西,弄清楚什么。所以任何帮助将不胜感激!

当前直播的形式:http://bit.ly/12yS1eh

HTML:

<div id="interested"> 
    <div class="content"> 
     <h2>INTERESTED?</h2> 
      <p>If you would like to stay up to date with upcoming content, release dates and chances to win signed prints of the photos, 
      just fill in your details below.</p> 
     <div id="thanks"></div> 
     <form action="javascript:alert('success!');" id="interestForm"> 
       <div id="formLeft"> 
         <input type="text" id="firstName" name="firstName" value="" placeholder="First name" /> 
         <input type="text" id="email" name="email" value="" placeholder="[email protected]" /> 
       </div> 

       <div id="formMiddle"> 
         <input type="text" id="lastName" name="lastName" value="" placeholder="Last name" /> 
         <input type="text" id="country" name="country" value="" placeholder="Your country" /> 
       </div> 

       <div id="formRight"> 
        <input type="submit" name="submit" value="SEND" id="submit" /> 
       </div> 
     </form> 
    </div> 
</div> 

的jQuery:

$(document).ready(function(){ 
$("#interestForm").submit(function(){ 

var str = $(this).serialize(); 

    $.ajax({ 
    type: "POST", 
    url: "contact_form/contact.php", 
    data: str, 
    success: function(msg){ 

$("#thanks").ajaxComplete(function(event, request, settings){ 

if(msg == 'OK') // If the email is sent show 'Thank You' message and hide the form 
{ 
result = '<div class="notification_ok">Thanks for registering your interest, we\'ll be in contact soon with more information about the iBook.</div>'; 
$("#interestForm").hide(); 
} 
else 
{ 
result = msg; 
} 

$(this).hide(); 
$(this).html(result).slideDown("slow"); 

$(this).html(result); 

}); 

} 

}); 

return false; 

}); 

}); 

PHP:

<?php 

include 'config.php'; 
    error_reporting (E_ALL^E_NOTICE); 
    $post = (!empty($_POST)) ? true : false; 

if($post) 
    { 
     include 'functions.php'; 
     $firstName = stripslashes($_POST['firstName']); 
     $lastName = stripslashes($_POST['lastName']); 
     $email = trim($_POST['email']); 
     $country = stripslashes($_POST['country']); 

     $message = ""; 
     $message .= "First Name: "; 
     $message .= $firstName; 
     $message .= "\n"; 
     $message .= "Last Name: "; 
     $message .= $lastName; 
     $message .= "\n"; 
     $message .= "Email: "; 
     $message .= $email; 
     $message .= "\n"; 
     $message .= "Country "; 
     $message .= $country; 


     $error = ''; 

// Check firstName 
if(!$firstName) 
    { 
     $error .= 'You forgot to enter your first name.<br />'; 
    } 

// Check lastName 
if(!$lastName) 
    { 
     $error .= 'You forgot to enter your last name.<br />'; 
    } 

// Check country 
if(!$country) 
    { 
     $error .= 'You forgot to enter your country.<br />'; 
    } 

// Check email 
if(!$email) 
    { 
     $error .= 'You forgot to enter your e-mail id.<br />'; 
    } 
if($email && !ValidateEmail($email)) 
    { 
     $error .= 'Invalid E-mail id !!!<br />'; 
    } 
if(!$error) 
    { 
     $subject = 'Hi, '.$firstName. ' ' .$lastName. ' is interested in Ireland - In a new light'; 
     $mail = mail(WEBMASTER_EMAIL, $subject, $message, 
      "From: ".$firstName." ".$lastName." <".$email.">\r\n" 
      ."Reply-To: ".$email."\r\n" 
      ."X-Mailer: PHP/" . phpversion()); 
if($mail) 
    { 
     echo 'OK'; 
    } 
} 
else 
    { 
     echo '<div class="notification_error">'.$error.'</div>'; 
    } 
} 
?> 

感谢提前任何帮助!

要连接的.ajaxComplete()处理程序错误。

在jQuery 1.8的,所述.ajaxComplete()方法只应附 来记录。

您可能还需要使用jQuery 1.9代替2.0(在IE不支持> 9)

可以删除处理(因为你没有真正使用它多少反正)

$(document).ready(function() { 
       $("#interestForm").submit(function() { 
        var str = $(this).serialize(); 
        var thx = $("#thanks"); 
        $.ajax({ 
         type: "POST", 
         url: "contact_form/contact.php", 
         data: str, 
         success: function(msg) { 

           if (msg == 'OK') // If the email is sent show 'Thank You' message and hide the form 
           { 
            result = '<div class="notification_ok">Thanks for registering your interest, we\'ll be in contact soon with more information about the iBook.</div>'; 
            $("#interestForm").hide(); 
           } 
           else 
           { 
            result = msg; 
           } 
           thx.hide(); 
           thx.html(result).slideDown("slow"); 

           //thx.html(result); <-- you don't need to put it 2 times 
         } 
        }); 
        return false; 
       }); 
      }); 

或者使用$(document).ajaxComplete();其他地方,但不是在success: function() {} ..

+0

作品像一个魅力amigo,真的很感激的帮助和知识,我没有意识到.ajaxComplete()只能附加到文件! – Michael

一堆你的JavaScript文件不加载:

  • JS /使用GreenSock/TweenMax.min.js
  • JS/jquery.superscrollorama.js
  • JS/smoothscroll.js
  • JS/jquery.cycle2.js
  • JS/Modernizr的-1.7.min.js

也许这是SOM用它来做什么?

也许并不是因为它们不是真正的验证脚本......但它是值得解决的,将其作为潜在问题折扣。另外你的CSS文件中的一个不加载任何

  • CSS/mob_global.css
+0

对不起,应该采取出来的我上传有版本(其整个网站的片段) - 无固定。不幸的是,虽然这不能解决任何问题,但是如果代码不在那里,代码就会绕过它们。 – Michael