title: jQuery form won't submit with reCAPTCHA 2
body: <p>I'm using HAML, Semantic UI and jQuery to generate my static site, and have a set of forms on a page which use reCAPTCHA v2.  My web implementer ran out of time on the project so I've picked up the slack, but only know a little Javascript/Semantic/jQuery.</p>
  
  <p>_header partial yields:
  <code>&lt;script src="https://www.google.com/recaptcha/api.js"&gt;&lt;/script&gt;</code></p>
  
  <p>my layout yields the form data:</p>
  
  <pre><code>&lt;form action='https://liveformhq.com/form/&lt;form uuid&gt;' class='ui large form' id='formGeneral' method='POST'&gt;
  &lt;snip&gt;
  &lt;label&gt;Message *&lt;/label&gt;
  &lt;textarea name='message' placeholder='Say hello'&gt;&lt;/textarea&gt;
  &lt;/div&gt;
  &lt;div class='field'&gt;
  &lt;div class='g-recaptcha' data-callback='reCaptcha_general' data-sitekey='&lt;my site key&gt;'&gt;&lt;/div&gt;
  &lt;input class='hiddenRecaptcha' id='gen_hiddenRecaptcha' name='gen_hiddenRecaptcha' type='hidden'&gt;
  &lt;button class='ui primary large button' type='submit'&gt;Send&lt;/button&gt;
  &lt;a class='item' href='#top' rel='scrolltoanchor'&gt;&amp;#x2B06;&lt;/a&gt;
  &lt;/div&gt;
  &lt;div class='ui error message'&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>_footer partial yields the jQuery which I comment on as we step through:</p>
  
  <p>I don't know why he used <code>$('form').form({</code> instead of <code>$('form').validate({</code> - Is this more recent jQuery?  It picks up the 'empty' reCAPTCHA box though.</p>
  
  <pre><code>  // form validation
    //
    $('form').form({
        on: 'blur',
        fields: {
  &lt;snip&gt;
            message: {
                identifier: 'message',
                rules: [{
                    type: 'empty',
                    prompt: 'Please enter your message'
                }]
            },
          gen_hiddenRecaptcha: {
              identifier: 'gen_hiddenRecaptcha',
              rules: [{
                  gen_hiddenRecaptcha: { required: true },
                  type: 'empty',
                  prompt: 'Please check the reCAPTCHA check box'
              }]
          },
        }
    });
  </code></pre>
  
  <p>This appears to be getting the response (I can alert and see the response come out) and this correctly affects the semantic warning which goes away when the field is no longer empty.</p>
  
  <pre><code>  var reCaptcha_general = function(response) {
        $("#gen_hiddenRecaptcha").val(response);
    };
  </code></pre>
  
  <p>And so below I think is the problem.  With all fields completed, the submit button doesn't work.  I may have confused two different approaches before and tried to solve the problem with both at the same time.</p>
  
  <p>When the submit is clicked, this function is called, but nothing happens.</p>
  
  <pre><code>  $('#formGeneral').submit(function(event) {
        if (!grecaptcha.getResponse()) {
            event.preventDefault(); //prevent form submit
            grecaptcha.execute();
        }
    });
  </code></pre>
  
  <p>UPDATE: I have just this edited in place as I have not had any answers yet.</p>
  
  <hr>
  
  <p>UPDATE2: In order not to skew the comments below (and bearing in mind at this time of writing no answers to the below questions are submitted), I updated the code and wanted to share this in case someone else gets tangled up in the same way.</p>
  
  <p>Revising <a href="https://developers.google.com/recaptcha/docs/verify" rel="nofollow noreferrer">the google docs</a> after seeing other questions warning of ensuring you validate the response token <em>separately</em>, the form element id is renamed to be clearer that it carries the response token payload:</p>
  
  <pre><code>&lt;div class="g-recaptcha" data-callback="reCaptcha_general" data-sitekey="&lt;site-key&gt;"&gt;
  &lt;input class="hiddenRecaptcha" id="gen_recaptchaResponseToken" name="gen_recaptchaResponseToken" type="hidden"&gt;
  </code></pre>
  
  <p>and in the footer, and this javascript to output warnings if the message box or reCAPTCHA are empty:</p>
  
  <pre><code>$('form').form({
      on: 'blur',
      fields: {
          message: {
              identifier: 'message',
              rules: [{
                  type: 'empty',
                  prompt: 'Please enter your message'
              }]
          },
          gen_recaptchaResponseToken: {
              identifier: 'gen_recaptchaResponseToken',
              rules: [{
                  gen_recaptchaResponseToken: { required: true },
                  type: 'empty',
                  prompt: 'Please check the reCAPTCHA check box'
              }]
          },
      }
  });
  </code></pre>
  
  <p>I thus updated the call back function with the new HTML form element ID: </p>
  
  <pre><code>var reCaptcha_general = function(response) {
      $("#gen_recaptchaResponseToken").val(response);
  };
  </code></pre>
  
  <p>and finally removed the grecaptcha.getResponse() call completely as per suggestion:</p>
  
  <pre><code>$('#formGeneral').submit(function(event) {
  }); 
  </code></pre>
  
  <p>and the form <em>functions</em> correctly.  I think the reason why it does is because my form validation service (the very excellent <a href="https://liveformhq.com/" rel="nofollow noreferrer">liveform</a>) have the secret I got when I signed up to the reCAPTCHA service with google.  I've not heard back from them as yet confirming what they technically do on the backend, but as the form action POSTs to a liveformhq.com URL, at the least, I expect them to be hitting Google's siteverify API to confirm the reCAPTCHA response token is valid.  </p>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>Am I right in thinking that with the above, I'm using jQuery form validation to prevent the form from being submitted by parsing the empty-ness of the response from the reCAPTCHA, rather than relying on <code>grecaptcha.getResponse()</code>?</p></li>
  <li><p>If so, do I even need the <code>grecaptcha.getResponse()</code> call?</p></li>
  <li><p>Although, am I right thinking that it is more secure to rely on <code>grecaptcha.getResponse()</code> and just make the jQuery form processing for that form element <code>required: true</code> just to get the warning prompt for the user?</p></li>
  </ol>