Recaptchav2 Invisible Error

Using Formit 4.2.6. Modx 2.8.1. PHP 7.3.

I’m trying to use recaptchav2 invisible but I’m getting the error…

“Please select the checkbox in the ReCaptcha image”

Do I need to call the invisible version a different way?

hooks=recaptchav2,FormItSaveForm,spam,email,redirect

I assume you use the extra ReCaptchaV2.
Do you call the right chunk recaptchav2_invisible_html?

<form id="login-form">
[[!recaptchav2_render?
    &tpl=`recaptchav2_invisible_html`
    &form_id=`login-form`
]]
</form>

Yeah this is what I’ve got…

[[!recaptchav2_render? &tpl=recaptchav2_invisible_html &form_id=mainform ]]

The chunk recaptchav2_invisible_html defines its own submit button (called “Login” by default).

<button type="submit" class="g-recaptcha" name="login" data-sitekey="[[+site_key]]" data-callback="recaptchaV2SubmitForm">Login</button>

I think you have to use this button instead of your own submit button to send the form.

Yep - that’s what I’m doing but just in case I’ve messed something up I’m going to go and grab the chunk from github and try it again

Using the chunk straight from github comes up with the same error.

The chunk I’m actually using is…

<script>function recaptchaV2SubmitForm(response){return new Promise(function(){document.getElementById('[[+form_id]]').submit();})}</script>
<div class="form-buttons text-right"><button input type="submit" class="g-recaptcha button hollow" name="submit_my_form" data-sitekey="[[+site_key]]" data-callback="recaptchaV2SubmitForm">Send Contact Inquiry</button></div>````

If I remove

recaptchav2

From the hooks the form works but does this mean it’s not then using recaptcha at all?

I would think so.


I tested it, and when I use the example form sample_formit_contact_form and then add a form id <form id="my_form_id" ...> and change

[[!recaptchav2_render]]

to

[[!recaptchav2_render?
	&tpl=`recaptchav2_invisible_html`
	&form_id=`my_form_id`
]]

and delete <input type="submit" value="Send" class="button" />, it works for me.


Are the keys from google that you are using for the correct version of v2?

The keys are for the right version and they are correct. It’s strange - with that hook removed I see the normal google recaptcha pop-up ‘Click all boxes with…’ message so something’s got to be working.

Looks like people have had this problem in the past…

Maybe to test what is going on, you could change this line in the snippet recaptchav2

to $modx->log(modX::LOG_LEVEL_ERROR, print_r($resp, true)); (or change the log_level in the system settings) to see the return of the verification in the error log.

You could also log the value of “g-recaptcha-response” to check that it is not empty.

$modx->log(modX::LOG_LEVEL_ERROR, 'g-recaptcha-response=' . $hook->getValue('g-recaptcha-response'));
1 Like

I’ll give that a go - thank you