Jump to content

Recommended Posts

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);

}

?>

Link to comment
https://forums.phpfreaks.com/topic/222765-php-form-with-captcha-amnyone-used-this/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.