Last active
February 21, 2019 08:05
-
-
Save fhdalikhan/892b7fc2ac92bdcac437f5c6c6569864 to your computer and use it in GitHub Desktop.
For Adding Recaptcha
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
// add js | |
<script src='https://www.google.com/recaptcha/api.js'></script> | |
// in html | |
<div class="g-recaptcha" data-sitekey="YOUR_SITEKEY"></div> | |
// for showing visual feedback if captcha is not selected | |
<script> | |
(function(){ | |
var formsToValidate = ['#YOUR_FORM_ID']; | |
formsToValidate.forEach(function(item){ | |
$(item).submit(function(event) { | |
var recaptcha = $(this).find('textarea[name=g-recaptcha-response]').val(); | |
if (recaptcha === "") { | |
event.preventDefault(); | |
$(this).find('.g-recaptcha > div').css('border', '1px solid red'); | |
} else { | |
$(this).find('.g-recaptcha > div').css('border', 'none'); | |
} | |
}); | |
}); | |
}()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment