Создание формы небольшого типа контакта для проекта, где люди могут регистрировать интерес к сайту, предоставляя несколько подробностей о себе. Поэтому я решил следовать этому руководству и изменить его в соответствии с моими потребностями: http://bit.ly/13zQ7emКонтактный формуляр, не анализирующий ошибки или сообщения об успешности
Я изменил PHP и jQuery, чтобы получить электронное письмо для отправки, которое сейчас делает, но я не могу понять, почему jQuery не запускает сообщение об успешном завершении, когда оно делает это, или выводит какие-либо ошибки при вводе некоторого числа.
Насколько я вижу, все должно срабатывать нормально, но я, очевидно, что-то пропустил, и я могу " t выяснить, что. Поэтому любая помощь будет принята с благодарностью!
Текущая живая форма: 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>';
}
}
?>
Спасибо за любую помощь заранее!
работает как шарм amigo, очень ценю помощь и знания, я не понимал, что .ajaxComplete() может быть прикреплен только к документу! – Michael