Last active
August 8, 2017 13:05
-
-
Save zahna/b302ee6d150405e5430855e53d5771ee to your computer and use it in GitHub Desktop.
render any number of recaptchas that are on a single page
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
In the page somewhere: | |
<script type="text/javascript" defer> | |
var gcRender = function() { | |
var sitekey, gcs, i, rcks, len; | |
sitekey = ''; | |
// Render all .g-recaptcha's on the page | |
gcs = document.getElementsByClassName('g-recaptcha'); | |
len = gcs.length; | |
for (i = 0; i < len; i++) { | |
grecaptcha.render(gcs[i], {'sitekey' : sitekey}); | |
} | |
// Add a value for the forms' recaptcha_keys | |
rcks = document.querySelectorAll('input[name=recaptcha_key]'); | |
len = rcks.length; | |
for (i = 0; i < len; i++) { | |
rcks[i].value = sitekey; | |
} | |
}; | |
</script> | |
<script src='https://www.google.com/recaptcha/api.js?onload=gcRender&render=explicit' async defer></script> | |
In each form: | |
<input type="hidden" name="recaptcha_key"> | |
<div class="g-recaptcha"></div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment