Note that there are some explanatory texts on larger screens.

plurals
  1. POReCaptcha validation with both PHP and jQuery
    primarykey
    data
    text
    <p>I'm trying to make a good registration form. At first I made a PHP validation script, because I know for sure that it is secure. When I posted my form incorrectly and got an error returned, all my input values were gone. I didn't like that so I learned about validation with Javascript. I don't have much experience with Javascript, but I've managed to validate my form with both client-side and server-side validation, except for the ReCaptcha field. </p> <p>The problem is that if I fill in the code correctly and press Submit, the client-side verification returns 'Succes' but the server-side validation always returns 'Wrong'. </p> <p>If I only validate with the server-side script it will return 'Succes' though, so the script itself is fine but somehow they won't work after each other with the same code. </p> <p><strong>Client-side recaptcha validation script:</strong> </p> <pre><code>function validateCaptcha() { challengeField = $("input#recaptcha_challenge_field").val(); responseField = $("input#recaptcha_response_field").val(); //console.log(challengeField); //console.log(responseField); //return false; var html = $.ajax({ type: "POST", url: "handlers/ajax.recaptcha.php", data: "recaptcha_challenge_field=" + challengeField + "&amp;recaptcha_response_field=" + responseField, async: false }).responseText; //console.log( html ); if(html == "success") { //Add the Action to the Form $("form").attr("action", "handlers/register_handler.php"); //Indicate a Successful Captcha $("#captchaStatus").html("Success!"); // Uncomment the following line in your application return true; } else { $("#captchaStatus").html("The security code you entered did not match. Please try again."); Recaptcha.reload(); return false; } } </code></pre> <p><strong>ajax.recaptcha.php</strong></p> <pre><code>&lt;?php require_once('recaptchalib.php'); $privatekey = "private key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($resp-&gt;is_valid) { echo "success"; } else { die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp-&gt;error . ")"); } ?&gt; </code></pre> <p><strong>Server-side recaptcha validation script:</strong> </p> <pre><code>require_once('recaptchalib.php'); $privatekey = "private key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp-&gt;is_valid) { echo "error"; } else { echo "succes"; } </code></pre> <p>They're both allmost the same, so I really don't know what I'm doing wrong here. </p> <p>Please help me out because I don't want to enter all the information again when I've only got the Captcha code wrong.</p> <p>Thanks in advance</p> <p>EDIT: I've discovered the fact that the same challenge field code is used for both client-side verification as the server-side verification. Maybe it won't work because the challenge field code can only be used once? If so, is there a way to make this work for me? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload