Validate Google reCaptcha in Magento 1.9

captchacontact-formform-validationgoogle apimagento-1.9

I have added the google recaptcha in contact us form but value is also submitting without captcha.
I have used in my contact page following codes for captcha:

 <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div> 
 <script src='https://www.google.com/recaptcha/api.js'></script>

These two code i have used. please tell me how can i validate captcha.

Best Answer

You should try this code: I have been using this on my site.

<script>
window.onload = function() {
  var recaptcha = document.forms["contactForm"]["g-recaptcha-response"];
  recaptcha.required = true;
  recaptcha.oninvalid = function(e) {

    alert("Please complete the captcha");
   }
}
</script>