How to use Invisible recaptcha inside jQuery?
This is recaptcha client side example: https://developers.google.com/recaptcha/docs/invisible#render_param
but all examples are in JavaScript, not jQuery.
I tried many times like below:
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
<script>
jQuery(function(){
$(document).on("click", "#submit", function(){
$("#demo-form").submit();
});
});
function onSubmit(token) {
document.getElementById("res").value = token;
}
var onloadCallback = function() {
grecaptcha.render('check', {
'sitekey' : 'site key',
'callback' : onSubmit
});
document.getElementById("check").click();
};
</script>
<form id='demo-form' action="test" method="POST">
<input type="text" id="res" value="" required/>
<button id="check" style="display:none;">Submit</button>
<button id="submit" type="button">go</button>
</form>
However, the code above does not work: required
attribute and jQuery's $("#demo-form").submit();
Other variants of the code were not successful either.
How can I use Google invisible recaptcha inside jQuery, and a working required
attribute?