I have two captcha on same form. One on submit and other on a modal which will open after form submit. So I render it after reading many answer from here. Now it is working fine with mozilla but giving reference error in chrome.
My google api is:
<script src='.js'></script>
Then my code renders this in java script:
$('.g-recaptcha').each(function(index, el) {
widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
});
My html read like this
<div id="user_recaptcha" class="reCaptcha">
<div id="e_Captcha" class="g-recaptcha" data-sitekey="<?php echo SITE_KEY; ?>" data-callback="recaptchaCallbackEvent"></div>
</div>
I declare widgetId
at the top of my js.
I have two captcha on same form. One on submit and other on a modal which will open after form submit. So I render it after reading many answer from here. Now it is working fine with mozilla but giving reference error in chrome.
My google api is:
<script src='https://www.google./recaptcha/api.js'></script>
Then my code renders this in java script:
$('.g-recaptcha').each(function(index, el) {
widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
});
My html read like this
<div id="user_recaptcha" class="reCaptcha">
<div id="e_Captcha" class="g-recaptcha" data-sitekey="<?php echo SITE_KEY; ?>" data-callback="recaptchaCallbackEvent"></div>
</div>
I declare widgetId
at the top of my js.
- Can u share some more of ur code so that I can get a better picture about it. Please add the html too. – Zac Commented Nov 8, 2017 at 11:05
1 Answer
Reset to default 4Recaptcha has a onload callback that will run once recaptcha is loaded. Place your code inside that callback function.
https://developers.google./recaptcha/docs/display
//call this function in your js
function onloadCallback() {
$('.g-recaptcha').each(function(index, el) {
widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
});
}
//load this script before your js is loading
<script src="https://www.google./recaptcha/api.js?onload=onloadCallback&render=explicit"></script>
//your html is absolutely fine.