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

Ryan Fung picture Ryan Fung · Jun 24, 2015 · Viewed 34.7k times · Source

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?

Answer

jagad89 picture jagad89 · Jun 24, 2015

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.