Google reCAPTCHA

by lemon kazi

HTML

<script src="https://www.google.com/recaptcha/api.js"></script>
<html>
<head>
<script>
  function onSubmit(token) {
  	console.log('Welcome human. Your token is ' + token);
    console.log(`server request to verify token : curl -d "secret=6LcgSAMTAAAAACc2C7rc6HB9ZmEX4SyB0bbAJvTG&response=${token}" https://www.google.com/recaptcha/api/siteverify`);
    alert('Captcha successfull : you\'re human');
  }

  function validate(event) {
  console.log('Calling Recaptcha API to verify humanity...');
    event.preventDefault();
      grecaptcha.execute();
  }

  function onload() {
    var element = document.getElementById('submit');
    element.onclick = validate;
    
    /* setTimeout(function(){
         document.getElementById('field').value="toto";
         document.getElementById('submit').click();
    }, 2000) */
    
    
  }
</script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
   <form>
       Code de parrainage :
       <input id="field" name="field">
       <button id='submit'>submit</button>
   </form>
   <div class="g-recaptcha"
       data-sitekey="6LcgSAMTAAAAACc2C7rc6HB9ZmEX4SyB0bbAJvTG"
       data-callback="onSubmit"
       data-theme="light"
       data-badge="inline"
       
   ></div>
<script>onload();</script>
</body>
</html>

CSS

.g-recaptcha{ 
    
}