I mean if I check first clients input and it is OK the second check of the same input is always false... Why is that?
I really need ability to check it twice (one for client side validation and second for server side validation)
Thanks in advance!!!
EDIT
Clarifying:
If user's input is ok and recaptcha returns true (I do it through ajax to my server which sends request to recaptcha's server) the form is submitting and sends via POST also 2 variables: recaptcha_challenge_field
value and recaptcha_response_field
value (which was already checked) and than my server asks recaptcha's server to check again this two values to do server side validation.
Jquery code:
$("#form_id").find("button").click(function(){
var c = $("#recaptcha_challenge_field").val(),
r = $("#recaptcha_response_field").val();
$.ajax({
url: "/ajax/captcha?challenge=" + c + "&response=" + r,
dataType: "json",
success: function(data){
if(data['is_valid']){
$.ajax({
url: "/ajax/captcha?challenge=" + c + "&response=" + r,
dataType: "json",
success: function(data){
if(data['is_valid']){
alert('OK');
}else{
alert('FAILED');
}
}
});
}else{
Recaptcha.reload();
}
}
});
return false;
});
So, as you can see there are two absolutely identical operations with different result (it alerts only FAILED
).
Because it is stored in a session that is cleared when the result is submitted. On page load, a new session variable for that CAPTCHA value is generated.
For validating Captcha twice via AJAX/Jquery and on a server page, this is my technique with PHP (the basic idea is just to restore Captcha's Session Variables cleared by the Captcha Check method if correct captcha entered on client side validation, so they will be there again for server side validation):
The following may look confusing as it is one of my lazy way of reusing the client side validation on both the HTML form and the HTML form's action page.
On the HTML form, add an additional POST variable (e.g. $_POST["task"] = "validate" which is not an input element in the form which will be passed on form submission to the client side validation PHP page
On the client side validation PHP page
On the server side validation page or form action url, you will have the Captcha Session intact for validation.