Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require User to click google's new recaptcha before form submission

Tags:

I am using google's new recaptcha inside my form (HTML5): https://www.google.com/recaptcha

Is there a way to check and mark recaptcha as required before form submission? I want to validate this on client side instead of server side. That way, I don't have to go back to the form and warn user about not entering anything for the captcha.

Any javascript that I can use to check whether user enter anything in recaptcha?

like image 778
Ryan Fung Avatar asked Jun 24 '15 03:06

Ryan Fung


People also ask

What is reCAPTCHA verification is required?

The reCAPTCHA Verification mechanism can provide protection against spam or abuse caused by robots. With this mechanism, the user is presented with a web page that contains a simple Turing test provided by the Google reCAPTCHA API. These tests can distinguish a human user from a robot.

Can I add reCAPTCHA to Google form?

To add a CAPTCHA field to your form, open the sidebar inside Google Sheet and expand the Advanced Settings section. Turn on the option that says "Include CAPTCHA" and save your changes.

How do I add reCAPTCHA validation?

Programmatically invoke the challenge To do this, you need to add a render parameter to the reCAPTCHA script load. Load the JavaScript API with your sitekey. Call grecaptcha.execute on each action you wish to protect. // Add your logic to submit to your backend server here.


1 Answers

You can check the textarea field with id g-recaptcha-response. You can do as following:

$("form").submit(function(event) {     var recaptcha = $("#g-recaptcha-response").val();    if (recaptcha === "") {       event.preventDefault();       alert("Please check the recaptcha");    } }); 

Hope this helps you.

like image 114
jagad89 Avatar answered Nov 09 '22 22:11

jagad89