Google ReCaptcha not posting 'g-recaptcha-resp

2019-04-03 21:32发布

This question has been asked before: New Google ReCaptcha not posting/receiving 'g-recaptcha-response' - but there was no proper answer.

I have the exact same set up as him, but the code fails here:

if(!$captcha){
   exit;
}

so $captcha=$_POST['g-recaptcha-response'] seems to be empty.

new google recaptcha with checkbox server side php = The 2nd answer here also doesn't seem to work.

Does anyone know why this could happen?

标签: php recaptcha
10条回答
【Aperson】
2楼-- · 2019-04-03 22:28

The perfect solution is do not create your own g-recaptcha-response input because google will fill it with the response and still yet go ahead creating another g-recaptcha-response textarea but then will not fill it with the response value

查看更多
太酷不给撩
3楼-- · 2019-04-03 22:31

It seems that Google wants your opening and closing tags to be outside of other DOM elements such as <table> or <div>. I had the exact same issue which is now resolved. Move your...

<div class="g-recaptcha" data-sitekey="abcd1234etc."></div>

...code to outside of any or tag and it will work. Seems as if Google cannot find the form and inject its form value otherwise.

查看更多
4楼-- · 2019-04-03 22:34

Today I had this same issue (g-recaptcha-response had no value upon submit) on a website of a colleague. Turns out that the tag <form was mistakenly nested right after the opening tag <table (not inside a td, but directly after <table).
This was causing the issue.
After moving the tag form in way it wrapped the table, the value of g-recaptcha-response was correctly posted to server side after submit.

查看更多
萌系小妹纸
5楼-- · 2019-04-03 22:35

Yes, the error is the DOM

Code error

table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"
form id="contacto" name="contacto" method="post" action="xxx"

Code OK


form id="contacto" name="contacto" method="post" action="xxx"
table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"
查看更多
登录 后发表回答