pixelchicken Posted December 27, 2010 Share Posted December 27, 2010 Hi all, I have found a thread that relates to my query but I'm a novice so it doesn't make any sense.. Basically, I have just implemented captcha on my site (php code below) and it's all working yey! All I need to do, is to alert the user if they enter an incorrect code, and *stay on the same page*. I have the alert working fine in Javascript, but it then takes the user to a blank page. I want to alert them (*you've entered a wrong code*) and then stay on the same page. Simple enough right? Any ideas grately appriciated! Code: <?php require_once('captcha/recaptchalib.php'); $privatekey = "6Lcil78SAAAAALYbGUXf2ophiajdWJuPho7A63La"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly ?> <script language="javascript"> alert("Verification words do not match image. Please try again."); </script> <? // **** NEED CODE HERE TO STAY ON SAME PAGE **** header( "Location: contact.php" ); } else { // Code here to handle a successful verification $to = "me@me.com"; $subject = "Contact / Booking Form from the Trevalia Website"; $name = $_REQUEST['name']; $email_field = $_POST['email']; $phone = $_POST['phone']; $comments = $_POST['comments']; *******"; $body = "From: $name \n\n E-Mail: $email_field\n\n Phone Number: $phone\n\n Message:\n $comments"; header( "Location: thankyou_contact.html" ); mail($to, $subject, $body, $headers); } ?> Quote Link to comment Share on other sites More sharing options...
PHPTOM Posted December 28, 2010 Share Posted December 28, 2010 So you are wanting the form to be submitted using AJAX so there is no refresh involved? Seems to me you have the line header( "Location: contact.php" ); which is refreshing the page aswell. Quote Link to comment Share on other sites More sharing options...
zkagenotora Posted December 29, 2010 Share Posted December 29, 2010 So you are wanting the form to be submitted using AJAX so there is no refresh involved? Seems to me you have the line header( "Location: contact.php" ); which is refreshing the page aswell. Like PHPTOM said, have you tried removing header( "Location: contact.php" ); ? From what I know, alert itself won't redirect a page. the only reason it redirects the page is because it executes redirection command, which is header( "Location: contact.php" ); in this case. FYI: I never use that particular library for CAPTCHA. However, I used CAPTCHA with other library before. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.