если вы взывали вначале рекапчу вот таким кодом (в теле html)
1 2 3 4 5 |
grecaptcha.ready(function () { grecaptcha.execute('код рекапчи', { action: 'contact' }).then(function (token) { $(".recaptcha_response").val(token); }); }); |
recaptcha_response — это инпут в теле формы. (форм может быть много, во все из них будет встроен один и тот же инпут)
То ее нужно встроить в submit сразу или же на ответ ajax.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$(document).ready(function () { $(".modal form").on('submit', function(){ var form=$(this); setTimeout(function() { /*$('.modal').removeClass("show"); $('.modal-backdrop').removeClass("show"); */ //вот эти строки дублированные grecaptcha.execute('кодрекапчи', { action: 'contact' }).then(function (token) { $(".recaptcha_response").val(token); }); }, 1500); }); }); |
вот как то так проверяется рекапча в php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
if (isset($_POST['recaptcha_response'])) { // Build POST request $recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify'; $recaptcha_secret = ' cecret code'; $recaptcha_response = $_POST['recaptcha_response']; // Make and decode POST request $recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response); $recaptcha = json_decode($recaptcha); // print_r($recaptcha); // Take action based on the score returned if ($recaptcha->score >= 0.1) { |