...

View Full Version : How to get ReCaptcha message displayed on form after button is pressed?



moss2076
11-21-2011, 01:53 AM
Hello,

I am trying to adjust my "contact.php" contact form to allow the use of ReCaptcha.

I am trying to get the message which appears when the typed words don't match or when they do match to appear below the submit button after it is pressed.

I am currently getting the message "The words didnt match. Please try again", when I press the submit button regardless of wether the words do actually match or not.
Here is my code -



<?php
$errors = null;


/*Re-captcha code starts here - linked to recaptchalib.php*/
require_once('recaptchalib.php');
$publickey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // you got this from the signup page
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";


if (isset($_POST['submit']))
{
$yourname = $_POST['yourname'];
$email = $_POST['email'];
$message = $_POST['message'];
$response = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if ($response->is_valid) {
echo "Yes, that was correct!"; }
else {
# set the error code so that we can display it
echo "The words didnt match. Please try again.";
}

// code to send email
if(count($errors)==0){

$to = 'me@me.com';
$subject = 'Email query from me.com';
$message = "Email sent from: $email \n $yourname has sent you a message:- \n $message";
$headers = 'From: queries@me.com' . "\r\n" .
'Reply-To: queries@me.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers) or exit('mail FAIL');
echo '<p>Thank you for emailing me! Your Message has been sent.</p>';
}
else
{
echo '<p>Please re-check your form entries.</P>';
}
}

/*Re-captcha code ends here*/

?>

<form id="tomsform" method="POST" action="<?php echo JRoute::_( 'index.php' );?>">

<p>Name</p>
<input type="text" name="yourname" size="19" value="<?php echo (isset($yourname)) ? $yourname : '';?>" class="textbox">
<?php
if(isset($errors['yourname'])) echo $errors['yourname'];
?>
<br>
<p>Email Address</p>
<input type="text" name="email" size="19" value="<?php echo (isset($email)) ? $email : '';?>" class="textbox">
<?php
if(isset($errors['email'])) echo $errors['email'];
?>
<br>
<p>Message</p>
<textarea rows="9" name="message" cols="30" class="textbox"><?php echo (isset($message)) ? $message: '';?></textarea>
<br>
<br>
<?php echo recaptcha_get_html($publickey, $errors); ?>
<input type="submit" value="Submit" name="submit" class="go">

</form>
<?php

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum