我的网站上有一个漂亮的上滑/下滑 jquery 表单。它将数据发送到同一文件以发送电子邮件。这工作正常:
$(document).ready(function(){
$('div.contact a.submit').click(function() {
var name = $('div.contact input.name').val();
var email = $('div.contact input.email').val();
var message = $('div.contact textarea.message').val();
$('div.contact').slideUp('slow', function() {
$.ajax({
type: "POST",
url: "test.php",
data: "name=" + name + "&email=" + email + "&message=" + message,
success: function(msg)
{
$('div.contact').html('<h1>Contact</h1><div class="comment">Success!</div><div class="clear"></div><p class="indent">Thank you, we will be in contact shortly.</p>');
$('div.contact').slideDown('slow');
}//end of success
});//end of ajax
});
});
});
test.php 顶部的 php 发送电子邮件:
include("expander-b1.0.php");
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
sendmail("admin@site.co.uk", $message, "Contact message from $name", $email);
这是从外部文件获取我的简单邮件功能。但是,我想要某种方法来验证表单条目(包括电子邮件验证),然后在联系潜水中显示错误。我对 jQuery 或 ajax 没有那么丰富的经验,但无法在我的 php 中使用 if 语句并在 ajax 的“成功”部分中回显变量。