Make google recaptcha required and submit comment

I have a website that is flooded by spammer…. I receive many spam comments and I’m sick to moderate them. So, I decided to add google recaptcha to my comment form (website by wordpress). The problem is I don’t know how to integrate it. I followed many tutorials online and I read many topics here but none worked on my website. I really appreciate any help.

The best/easy tutorial I followed is that to add a required hidden input before

Read More
<div id="rcaptcha" class="g-recaptcha" data-sitekey="">

But I can’t submit the comment even when I solved the recaptcha. I tried many jquery codes to make a link between that hidden input and the recaptcha (so if I solve the recpatcha I can then submit the comment) but none worked. The input is like:

<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptchaa">

The best validation coded (I added in the head — PS: My site have the jquery.validate.js):

var validator = $("#commentsubmit").validate({
   ignore: ".ignore",
   rules: {
       "hiddenRecaptcha": {
           required: function() {
               if(grecaptcha.getResponse() == '') {
                   return true;
               } else {
                   return false;
               }
           }
       }
   }
});

but not worked. So I thought somehow to change the strategy, like if I solve the recaptcha then the class=required from the input disappear (removed) so then I can submit the the comment. But again I didn’t succeed.
So, some ideas?

Related posts

1 comment

  1. I think that you have to change the ignore rule to this:

    ignore: [],

    Or in case you really need to something being ignored during the validation:

    ignore:".ignore, :not(:visible,.hiddenRecaptcha)",

Comments are closed.