Last active
March 13, 2022 23:42
-
-
Save man4toman/0940d69160f5479f4c4a8d0dcf2c2ad4 to your computer and use it in GitHub Desktop.
Google recaptcha v3 - JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post"> | |
<div class="g-recaptcha" data-sitekey="SITE_KEY" data-callback="verifyCaptcha"></div> | |
<div id="g-recaptcha-error"></div> | |
<input type="button" class="submit" value="Submit" /> | |
</form> | |
<script src='https://www.google.com/recaptcha/api.js'></script> | |
<script> | |
var recaptcha_response = ''; | |
jQuery('.submit').on('click', function(){ | |
if(recaptcha_response.length == 0) { | |
document.getElementById('g-recaptcha-error').innerHTML = '<span style="color:red;">This field is required.</span>'; | |
return false; | |
} | |
return true; | |
}) | |
function verifyCaptcha(token) { | |
recaptcha_response = token; | |
document.getElementById('g-recaptcha-error').innerHTML = ''; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment