Help please solve the problem. There is an HTML feedback form with ajax request. I can not screw reCAPTCHA to it. Without ajax, everything works fine (the Form sends a letter only in the case of validation of a captcha), but with ajax it does not work, it just goes without a captcha
Ajax request
$(document).ready(function() { $("#feedback-form").submit(function() { $.ajax({ type: "POST", url: "send.php", data: $(this).serialize() }).done(function() { $(this).find("input").val(""); $("#feedback-form").trigger("reset"); document.getElementById('results' ).style.display = 'block'; }); return false; });
});
Php handler
if($_SERVER['REQUEST_METHOD'] == 'POST') { if (empty($_POST['g-recaptcha-response'])) { exit('Empty'); } $url = 'https://www.google.com/recaptcha/api/siteverify'; $recaptcha = $_POST['g-recaptcha-response']; $secret = 'мой_секретный_ключ'; $ip = $_SERVER['REMOTE_ADDR']; $url_data = $url.'?secret='.$secret.'&response='.$recaptcha.'&remoteip='. $ip; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url_data); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($curl); curl_close($curl); $res = json_decode($res); if($res->success) { echo 'YES'; } else { exit('Error'); } } if((isset($_POST['name'])&&$_POST['name']!="") &&(isset($_POST['email'])&&$_POST['email']!="") &&(isset($_POST['message'])&&$_POST['message']!="")) { $to = "почта"; $name = trim($_POST["name"]); $email = trim($_POST["email"]); $message = trim($_POST["message"]); $message = "Имя: $name \nEmail: $email \nСообщение: $message"; $pagetitle = "Новое сообщение"; mail($to, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $email"); }
post
method usingajax
. Is there ag-recaptcha-response
with a value? Your question is simple, I can help without any problems! Yesterday I just helped to solve the issue on the same captcha. Link to stackoverflow - Dmitry