Skip to content

Recaptcha Without Form Submit via Link

Ryan Fox edited this page Jul 11, 2017 · 1 revision

I needed to check recaptcha without submitting my form. You can add the g-recaptcha-response to your request manually:

= f.input :username
= link_to "check availability", is_username_available_path, id: "check_username", remote: true
= recaptcha_tags ajax: true

$("#check_username").on('click', function() { 
  username = $("input[name='your_form[username]']").val();
  recaptcha = $("#g-recaptcha-response").val();
  $(this).data("params", "username=" + username + "&g-recaptcha-response=" + recaptcha);
});

If you need to submit multiple times, in js reponse: grecaptcha.reset();