我需要得到这个来区分成功和失败的提交。
发送电子邮件.php
$name = trim($_REQUEST['name']);
$email = trim($_REQUEST['email']);
$content = $_REQUEST['comment'];
if (eregi("\r",$email) || eregi("\n",$email)){
die("Why ?? :(");
}
$sitemail = "mail@mysite.com";
$ip='none';
$ip = getenv('REMOTE_ADDR');
if( $_SESSION['security_code'] != $_POST['security_code'] || empty($_SESSION['security_code'] ) ) {
echo'<div class="message">The security code you entered did not match the image.</div>';
return false;
}
else{
//$sent=mail( $sitemail, "Message Title","From: $name \n \n $message \n\n $ip", "From: $email" );
echo'<div class="message">Thank you for your message. We will get back to you as soon as possible.</div>';
}
查询:
jQuery("#contact-form").submit(function(e){
var $form = jQuery(this),
$msg = jQuery(this).prev('div.message'),
$action = $form.attr('action');
jQuery.post($action,$form.serialize(),function(data){
$form.fadeOut("fast", function(){
$msg.hide().html(data).show('fast');
});
});
e.preventDefault();
});
形式
<div class="message"></div>
<form id="contact-form" method="post" action="send-email.php">
<p class="column one-half">
<input name="name" type="text" placeholder="Your Name" required >
</p>
<p class="column one-half last">
<input name="email" type="email" placeholder="Your Email" required >
</p>
<p class="clear"><textarea name="comment" placeholder="Your Message" cols="5" rows="3" required></textarea>
</p>
<p class="column one-third"><input id="security_code" type="text" placeholder="Enter Code in image" name="security_code" required></p>
<img src="captcha/verifyimg.php?width=192&height=48" alt="Image verification" align="left" style="margin:10px;" />
<p><input name="submit" type="submit" value="Send Message">
</p>
</form>
如果表单在 security_code 上失败,我希望能够让表单保持可见。
因此,可能需要来自 send-email.php 的响应,然后与“if”子句一起使用。我已经尝试了几种方法来做到这一点,甚至无法区分回调结果!我似乎只是在兜圈子。任何帮助表示赞赏。