Last active
November 20, 2017 12:16
-
-
Save vishnusomanus/8d8384b9b016eb25b5e728aa8a2eb0e0 to your computer and use it in GitHub Desktop.
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
<div class="container"> | |
<div id="recaptcha1"></div> | |
<div id="recaptcha2"></div> | |
<div id="recaptcha3"></div> | |
<div id="recaptcha4"></div> | |
<div id="recaptcha5"></div> | |
</div> <!-- /container --> | |
<script src="https://www.google.com/recaptcha/api.js?onload=myCallBack&render=explicit" async defer></script> | |
<script> | |
var recaptcha1; | |
var recaptcha2; | |
var recaptcha3; | |
var recaptcha4; | |
var recaptcha5; | |
var myCallBack = function() { | |
recaptcha1 = grecaptcha.render('recaptcha1', { | |
'sitekey' : '6LfvUQ8UAAAAAA9T-1xvolQ3DbkB1TnyaCabMqyT', | |
'theme' : 'light' | |
}); | |
recaptcha2 = grecaptcha.render('recaptcha2', { | |
'sitekey' : '6LfvUQ8UAAAAAA9T-1xvolQ3DbkB1TnyaCabMqyT', | |
'theme' : 'light' | |
}); | |
recaptcha3 = grecaptcha.render('recaptcha3', { | |
'sitekey' : '6LfvUQ8UAAAAAA9T-1xvolQ3DbkB1TnyaCabMqyT', | |
'theme' : 'light' | |
}); | |
recaptcha4 = grecaptcha.render('recaptcha4', { | |
'sitekey' : '6LfvUQ8UAAAAAA9T-1xvolQ3DbkB1TnyaCabMqyT', | |
'theme' : 'light' | |
}); | |
recaptcha5 = grecaptcha.render('recaptcha5', { | |
'sitekey' : '6LfvUQ8UAAAAAA9T-1xvolQ3DbkB1TnyaCabMqyT', | |
'theme' : 'light' | |
}); | |
}; | |
/*Verification and validation*/ | |
/* | |
*. Add a custom attribute ( reca ) for each form. | |
*. reca value is captcha index in myCallBack function. | |
*. for only one captcha validation use second code | |
*/ | |
/*code1 (for multiple forms)*/ | |
$('.modal-content form, form#contactform').submit( | |
function(e) | |
{ | |
var reca = $(this).attr('reca'); | |
e.preventDefault(); | |
var response = grecaptcha.getResponse( reca ); | |
if(response=='') | |
{ | |
e.preventDefault(); | |
$(this).find('#recaptcha-error').html("This field is required.").show(); | |
} | |
else $(this).find('#recaptcha-error').html("This field is required.").hide(); | |
} | |
); | |
/* code2 (for single form) */ | |
$('form#contactform').submit( | |
function(e) | |
{ | |
var response = grecaptcha.getResponse( ); | |
if(response=='') | |
{ | |
e.preventDefault(); | |
$(this).find('#recaptcha-error').html("This field is required.").show(); | |
} | |
else $(this).find('#recaptcha-error').html("This field is required.").hide(); | |
} | |
); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment