我想为我的联系表单添加reCaptcha,但它不起作用。我总是得到reCaptcha没有正确输入!
这是我的网站:http://ramzi-bk.net84.net/
在cantact.php中
<form action="">
...
<div class="box-wrapper" id="recaptcha_div"></div>
<input value="Envoyer" class="submit btn-form" id="submit" type="submit"/>
</form>
在external.js
中var options = {
type: "POST",
url: 'service/sendMail.php', // override for form's 'action' attribute
error: mailError,
success: mailResponse, // post-submit callback
beforeSubmit: validate,
clearForm: false, // clear all form fields after successful submit
resetForm: false, // reset the form after successful submit
};
$('#contactForm').ajaxForm(options);
function mailResponse(data,textStatus,xhr,jqXHR){
showMsg(data);
}
function mailError(jqXHR,textStatus,errorThrown){
showMsg(errorThrown);
}
function showRecaptcha(element) {
Recaptcha.create("**********************", element, {
theme: "white",
callback: Recaptcha.focus_response_field});
}
showRecaptcha("recaptcha_div");
在sendMail.php中
<?php
require_once('../lib/recaptchalib.php');
$privatekey="***********************";
$resp=recaptcha_check_answer($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if(!$resp->is_valide){
echo "The reCAPTCHA wasn't entered correctly: ".$resp->error;
}else{
/* Envoi de l'e-mail */
if(mail($to, $subject, $msg, $headers)==true){
echo "Votre message a été envoyé.";
}else{
echo "Une erreur s'est produite lors de l'envoi de votre message.";
}
/* clear form variables*/
unset($_POST);
}
请帮忙。