I am trying to implement Google\'s reCaptcha v.2.0 but i am getting null in g-recaptcha-response due to this reCaptcha is not working properly and I am always g
I've run into the same issue. The strangest part is a client-side call to grecaptcha.getResponse()
returns to correct response. For some reason it's just not setting g-recaptcha-response.
So my workaround was to set a data-callback function to populate a hidden field with the response and use that server-side instead. The hidden input also helps with ease of client-side validation.
eg:
javascript:
function captcha_onclick() {
document.getElementById('recaptchaValidator').value = grecaptcha.getResponse();
}
server-side:
if(!empty($_POST['recaptcha'])) {
$captcha = $_POST['recaptcha'];
...
}