0

Resumen

Intento implementar el recaptcha de google en mi formulario pero me sale un error de javascript. El error es así en consola

index.php:288 Uncaught (in promise) ReferenceError: $ is not defined at index.php:288:7

Problema

Segun el video que ví y me estoy guiando para implementar recaptcha el código está bien, igual al mio ...

Aquí llamo la API de Google incluyendo las contraseñas

<!--ReCapcha-->
    <script src="https://www.google.com/recaptcha/api.js?render=<?php echo SITE_KEY;?>"></script>
    <!---->

HTML

<from action="" method="post" id="loginForm"> 

        <input type="text" name="entrar" id="entrar">

        <button type="button"   class="formulario__btn">Enviar</button>

    </from>

PHP con salida en javascript

<script type="text/Javascript"> 
                grecaptcha.ready(function(){

                    grecaptcha.execute('<?php echo SITE_KEY;?>', {action: 'homepage'}).then(function(token) {

                        console.log(token);

                        $('#entrar').val(token);
                    });
                });
            </script>

1
  • 2
    ¿Tienes agregado JQuery en la ubicación correcta dentro de tu documento? el 1 mar. 2022 a las 17:59

2 respuestas 2

0

la solución era muy simple, tengo que darle el token al JS de diferente manera, asi:


<script type="text/Javascript"> 
               grecaptcha.ready(function(){

                   grecaptcha.execute('<?php echo SITE_KEY;?>', {action: 'homepage'}).then(function(token) {
                       document.getElementById("entrar").value = token;
                   });
               });
           </script>
1
  • 2
    Es decir, estabas intentando usar sintaxis que requiere JQuery y, al usar Javascript común y corriente, funcionó :)
    – Alfabravo
    el 1 mar. 2022 a las 18:21
0

La respuesta era ... muy simple, solo debia de implementar la libreria de Jquery

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.