Hi!
here is a way that worked for me:
- as it says in doc's that your should save the used captcha-response to prevent multiple use, i came to the conclusion that it can only be checked reliable serverside.
so we hang on form's submit, ask the server, server shall tell us if g-recaptcha-response was posted, then we show to the user.. in this case alert...
begin jscode:
$(function() {
//hang on event of form
$("#responseform").submit(function(e) {
//prevent Default functionality
e.preventDefault();
//get the action-url of the form
var actionurl = e.currentTarget.action;
//do your own request an handle the results
$.ajax({
url: actionurl,
type: 'post',
dataType: 'json',
data: $("#responseform").serialize(),
success: function(data) {
if(data.status == "error") {
alert("please fill in the captcha....");
}
else {
alert("ok, got your message! thank you!");
}
},
fail: function(data) {
}
});
});
});
-- end code
here on server side ( php )
begin code:
$resp = $this->input->post("g-recaptcha-response");
//if the g-recaptcha-response is not in post, or set to unreasonable value, abort.
if($resp == null || strlen($resp) < 2) {
$response_array['message'] = 'captcha was not solved.';
$response_array['status'] = 'error';
header('Content-type: application/json');
echo json_encode($response_array);
die();
}
-- end code
since im also playing with this i put something together here:
hope it helps someone...
greetings
chris