locked
Validate reCAPTCHA client side before post for server side validation RRS feed

  • Question

  • User1953081067 posted

    Hi,

    I've created the reCAPTCHA for .NET using the following: https://www.codeproject.com/Tips/884193/Google-ReCaptcha-ASP-net-Control

    I've got it working in that when I submit, the server side validation works and does the job. But what I'd like is some client slide validation of the check box before the form is submitted to make it easier for the user.

    I've added  OnClientClick="test()" to my button, then the following JS in the HEAD:

        <script>
            function test() {
                alert('Here');
                if (ctrlGoogleReCaptcha.Validate())
                {
                   //submit form success
                   //lblStatus.Text = "Success";
                }
                else
                {
                    //captcha challenge failed
                    //lblStatus.Text = "Captcha Failed!! Please try again!!";
                    alert('Not valid');
                }
            }
        </script>

    But this isn't working.

    Any ideas?

    Thanks as always

    Sunday, November 29, 2020 11:58 PM

Answers

  • User-939850651 posted

    Hi RichardLaw,

    Have you checked the error message in the console? I think the server code you provided is not applicable to the client.

    But if you need to verify reCAPTCHA from the client side, you could try to get response from the reCAPTCHA to judge its length.

    Please refer to the answer in this case below:

    How can I validate google reCAPTCHA v2 using javascript/jQuery?

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2020 7:59 AM

All replies

  • User-939850651 posted

    Hi RichardLaw,

    Have you checked the error message in the console? I think the server code you provided is not applicable to the client.

    But if you need to verify reCAPTCHA from the client side, you could try to get response from the reCAPTCHA to judge its length.

    Please refer to the answer in this case below:

    How can I validate google reCAPTCHA v2 using javascript/jQuery?

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2020 7:59 AM
  • User1953081067 posted

    Thanks so much. I'd spent ages Googling this and trying different things. In the end, so simple.

    Thanks again

    Monday, November 30, 2020 8:55 AM