nenes25/eicaptcha

Uncaught (in promise) TypeError: recaptchaResponse is null

Closed this issue · 8 comments

Check if your issue exists

  • I confirm that i've search that my issue does not already exists

Your prestashop version

8.1.x

Eicaptcha version

2.5.x

Do you use a specific theme ?

Yes

https://lartdelabiere.fr/nous-contacter

Describe the bug

I'd like to use the module with v3, but it's not possible. I get an error when I click 'send' on the contact form. It seems like it's not retrieving the value from the input in the form, which is weird. I looked at the code a bit and realized that the API is not the same, here are my instructions :

<head>
  <script src="https://www.google.com/recaptcha/enterprise.js?render=6LelJ30pAAAAANSxkh9W5zeVUcq7Hm2eWx5DIChb"></script>
  <!-- Your code -->
</head>

<script>
  function onClick(e) {
    e.preventDefault();
    grecaptcha.enterprise.ready(async () => {
      const token = await grecaptcha.enterprise.execute('6LelJ30pAAAAANSxkh9W5zeVUcq7Hm2eWx5DIChb', {action: 'LOGIN'});
    });
  }
</script>

I think this has nothing to do with my problem but it's just for your information.

Screenshots

Uncaught (in promise) TypeError: recaptchaResponse is null


<script>
            grecaptcha.ready(function () {
                grecaptcha.execute("6LelJ30pAAAAANSxkh9W5zeVUcq7Hm2eWx5DIChb", {action: "contact"}).then(function (token) {
                    var recaptchaResponse = document.getElementById("captcha-box");
                    recaptchaResponse.value = token;
                    });
                });
 </script>

Additional context

id="captcha-box" value="03AFcWeA6BXUw5tGeO2MW0iew5KN7WVALV_GyDItZUldUEj9_NK0K-6uixm2MH4Z-I01rSg_j19qxmwh--880qVqsRZmubeln4gdgAo2rcuWDi6sBGApCj9SqbNEkfW2k5uCMdrVH50b7WNdcUPzrIWkXfM8jlohdcnmlRlRuUykbf89jxM33kLz9x9KgCLJBxsX1JcQIKOVKhfMv8-2d72RrxNomI-XPpEpyzwkKwxFfOS3cz-2Dy72CQsOStypf6OkmWhHHPpQNfDltoNFfRNKJya4hy6zTBYlYKbyZEhknjS3ZvriILxaOQ269Yw1B9zpkw76Cqaz4fMCW1VWfUTzCeWJeb71cYRLN9xDN7bGAEeg9ERo-i6SFa1KoHPK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FDeblsDt5-xFHJ6l5X9oxxWgZ1QxgDLM1n_EuY6Jm4g1Z6_c-zLcRPrg3OIixs6AM9_WysZKDvYc9v-6_OI3owQGb98FWirwFsvm7HZrgqJXfVIBN3CHXVo6N4U6d2DYguJSMoop6WUN4ErLsGnIw5amrpkP6h0EHYMCMgxn-owejoIcdYznzVQ4lRPMIowu_9LzZY_OFFV3G7VCDGqGbBAhpnni8bfxReBpgbT_dVjid0r1xrt_tC9Jj-5dYzDdRzvTvyirmNd5Rnwtn4rke-rWOHLvmXws5j91KkcKvvadw" name="g-recaptcha-response"

Same problem here

I tried the form create account page and it works on this page. The bug occure only on contact form page

This:

<script>
            grecaptcha.ready(function () {
                grecaptcha.execute("6LelJ30pAAAAANSxkh9W5zeVUcq7Hm2eWx5DIChb", {action: "contact"}).then(function (token) {
                    var recaptchaResponse = document.getElementById("captcha-box");
                    recaptchaResponse.value = token;
                    });
                });
 </script>

Means balise with id captcha-box was not found.

Problem can be fixed by following this explanation: https://www.h-hennes.fr/blog/module-recaptcha-pour-le-formulaire-de-contact-prestashop/

Le module ajoute dynamiquement une balise html <div id= »captcha-box »></div> à la fin du formulaire de contact, le captcha est ensuite ajouté automatiquement dans cette balise par le script recaptcha.

Sur certains thèmes spécifiques l’ajout de cette balise ne fonctionne pas correctement.
Le plus simple pour le corriger est d’ajouter manuellement le code:

`<div id="captcha-box"></div>`


dans le template du formulaire de contact qui est situé dans themes/votretheme/<strong>contact-form.tpl</strong> avant la fin de la balise &lt;/form&gt; ( libre à vous d’adapter ensuite son affichage )

This:

<script>
            grecaptcha.ready(function () {
                grecaptcha.execute("6LelJ30pAAAAANSxkh9W5zeVUcq7Hm2eWx5DIChb", {action: "contact"}).then(function (token) {
                    var recaptchaResponse = document.getElementById("captcha-box");
                    recaptchaResponse.value = token;
                    });
                });
 </script>

Means balise with id captcha-box was not found.

Problem can be fixed by following this explanation: https://www.h-hennes.fr/blog/module-recaptcha-pour-le-formulaire-de-contact-prestashop/

Le module ajoute dynamiquement une balise html <div id= »captcha-box »></div> à la fin du formulaire de contact, le captcha est ensuite ajouté automatiquement dans cette balise par le script recaptcha.

Sur certains thèmes spécifiques l’ajout de cette balise ne fonctionne pas correctement.
Le plus simple pour le corriger est d’ajouter manuellement le code:

`<div id="captcha-box"></div>`


dans le template du formulaire de contact qui est situé dans themes/votretheme/<strong>contact-form.tpl</strong> avant la fin de la balise &lt;/form&gt; ( libre à vous d’adapter ensuite son affichage )

I've already tried to do it, but that's not the issue for two reasons:

So unless I'm mistaken, I don't quite understand where the problem could be coming from.

It's Prestashop 8.0.5 and I'm French if you need help!

Thx

If you want use capcha v2 you have to create a key specialy for it here : https://www.google.com/recaptcha/admin/

(I struggle to find it out to...)

If you want use capcha v2 you have to create a key specialy for it here : https://www.google.com/recaptcha/admin/

(I struggle to find it out to...)

Thanks ! But I prefer v3 🥲

You can close the issue, I will look for another solution 😉

Hello,

Thanks for your feedback
I need to check the behavior with the enterprise version.
But with the standard version both v2 and v3 keys are working.

Regards,

Hello,

Thanks for your feedback I need to check the behavior with the enterprise version. But with the standard version both v2 and v3 keys are working.

Regards,

Yes, it's true !