I need to get this to distinguish between a successful and a failed submission.
send-email.php
$name = trim($_REQUEST['name']);
$email = trim($_REQUEST['email']);
$content = $_REQUEST['comment'];
if (eregi("",$email) || eregi("
",$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
$message
$ip", "From: $email" );
echo'<div class="message">Thank you for your message. We will get back to you as soon as possible.</div>';
}
Jquery:
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();
});
form
<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>
I want to be able to get the form to stay visible if the form fails on the security_code.
So perhaps a response from the send-email.php is needed and then used with an 'if' clause. I have tried several ways to do this and couldn't even get it to distinguish between the callback results! I just seem to have gone round in circles. Any help appreciated.