Php 联系人表单未分析错误或成功消息
为一个项目创建一个小型的联系人类型表单,人们可以在该表单中注册对该站点的兴趣,并提供一些关于他们自己的详细信息。因此,我决定遵循本教程并对其进行修改以满足我的需要: 我修改了PHP和jQuery以获得要发送的电子邮件,它现在可以发送,但是我不明白为什么jQuery在发送成功消息时没有触发成功消息,或者在键入一些消息时没有显示任何错误 就我所见,一切都应该顺利,但我显然错过了一些东西,我不知道是什么。因此,任何帮助都将不胜感激 当前直播形式: HTML:Php 联系人表单未分析错误或成功消息,php,javascript,jquery,html,Php,Javascript,Jquery,Html,为一个项目创建一个小型的联系人类型表单,人们可以在该表单中注册对该站点的兴趣,并提供一些关于他们自己的详细信息。因此,我决定遵循本教程并对其进行修改以满足我的需要: 我修改了PHP和jQuery以获得要发送的电子邮件,它现在可以发送,但是我不明白为什么jQuery在发送成功消息时没有触发成功消息,或者在键入一些消息时没有显示任何错误 就我所见,一切都应该顺利,但我显然错过了一些东西,我不知道是什么。因此,任何帮助都将不胜感激 当前直播形式: HTML: <div id="intereste
<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;
});
});
$(文档).ready(函数(){
$(“#interestForm”).submit(函数(){
var str=$(this.serialize();
$.ajax({
类型:“POST”,
url:“contact_form/contact.php”,
数据:str,
成功:功能(msg){
$(“#谢谢”).ajaxComplete(功能(事件、请求、设置){
if(msg==“OK”)//如果发送了电子邮件,则显示“谢谢”消息并隐藏表单
{
结果='感谢您的关注,我们将很快与您联系,了解有关iBook的更多信息。';
$(“#interestForm”).hide();
}
其他的
{
结果=味精;
}
$(this.hide();
$(this.html(result).slideDown(“slow”);
$(this).html(result);
});
}
});
返回false;
});
});
PHP:
提前谢谢你的帮助 大量javascript文件无法加载:
- js/greensock/TweenMax.min.js
- js/jquery.superscrollarma.js
- js/smoothscroll.js
- js/jquery.cycle2.js
- js/modernizer-1.7.min.js
- css/mob_global.css
.ajaxComplete()
处理程序错误
从jQuery1.8开始,只应附加.ajaxComplete()方法
记录
您可能还希望使用jquery1.9
而不是2.0
(IE>9不支持)
您可以删除处理程序(因为您实际上并不经常使用它)
$(文档).ready(函数(){
$(“#interestForm”).submit(函数(){
var str=$(this.serialize();
var thx=$(“#谢谢”);
$.ajax({
类型:“POST”,
url:“contact_form/contact.php”,
数据:str,
成功:功能(msg){
if(msg==“OK”)//如果发送了电子邮件,则显示“谢谢”消息并隐藏表单
{
结果='感谢您的关注,我们将很快与您联系,了解有关iBook的更多信息。';
$(“#interestForm”).hide();
}
其他的
{
结果=味精;
}
thx.hide();
html(result.slideDown(“slow”);
//thx.html(result);对不起,我应该从我上传到那里的版本中删除它(它是整个网站的一个片段)-现在已经修复。不幸的是,虽然这并不能修复任何问题,但如果它们不在那里,代码只会绕过它们。就像一个迷人的朋友,非常感谢您的帮助和知识,我没有意识到。ajaxComplete()只能附加到文档!
<?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>';
}
}
?>
$(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;
});
});