0

为项目创建一个小型联系类型表单,人们可以在其中注册对该站点的兴趣,并提供一些关于他们自己的详细信息。所以我决定按照本教程进行修改以适应我的需要:http ://bit.ly/13zQ7em

我已经修改了 PHP 和 jQuery 以便让​​电子邮件发送,它现在可以发送,但是我无法弄清楚为什么 jQuery 在这样做时没有触发成功消息,或者在我输入一些内容时显示任何错误.

据我所见,一切都应该正常,但我显然错过了一些东西,我不知道是什么。所以任何帮助将不胜感激!

当前直播形式: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@email.com" />
                </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>';
    }
}
?>

提前感谢您的帮助!

4

2 回答 2

1

.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() {} ..

于 2013-05-16T23:06:27.497 回答
0

一堆你的 javascript 文件没有加载:

  • js/greensock/TweenMax.min.js
  • js/jquery.superscrollorama.js
  • js/smoothscroll.js
  • js/jquery.cycle2.js
  • js/modernizr-1.7.min.js

可能与它有关吗?

也许不是因为它们不是真正的验证脚本......但值得修复它以将其视为潜在问题。此外,您的 CSS 文件之一也不会加载

  • css/mob_global.css
于 2013-05-16T22:55:08.580 回答