Код: Выделить всё
function recaptchaOnload() {
"use strict";
$(".g-recaptcha").each(function () {
var reCaptcha = $(this);
var recaptchaClientId = grecaptcha.render(reCaptcha.attr("id"), {
"callback": function (response) {
document.getElementById(reCaptcha.closest('form').attr('id')).submit();
},
"sitekey": '$this->siteKey',
"size": "invisible"
});
reCaptcha.closest('form').on('beforeSubmit',function(){
grecaptcha.execute(recaptchaClientId);
});
});
}
Код: Выделить всё
$('form').submit(function () {
console.log('2222222');
return false;
});
Пробовала менять reCaptcha.closest('form').on('beforeSubmit',function(){ на reCaptcha.closest('form').submit(function() { Толку нет.
Функция function recaptchaOnload() идет в виджете и там писать код, нужный только в одном случае для конкретной формы не хотелось бы.
Пыталась реализовать через код
Код: Выделить всё
<script>
grecaptcha.ready(function() {
// do request for recaptcha token
// response is promise with passed token
grecaptcha.execute('your reCAPTCHA site key here', {action:'validate_captcha'})
.then(function(token) {
// add token value to form
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>