parent
2ac1781118
commit
f4cf194638
8 changed files with 58 additions and 51 deletions
@ -1,15 +0,0 @@ |
||||
--- |
||||
--- |
||||
|
||||
<script src='./captcha.js'></script> |
||||
|
||||
<script |
||||
src='https://www.google.com/recaptcha/api.js?onload=onCaptchaLoad&render=explicit' |
||||
async |
||||
defer |
||||
></script> |
||||
|
||||
<!-- Captcha form start --> |
||||
<div class='recaptcha-field mb-2'></div> |
||||
<input type='hidden' name='g-recaptcha-response' class='recaptcha-response' /> |
||||
<!-- Catpcha form end --> |
@ -0,0 +1,5 @@ |
||||
--- |
||||
--- |
||||
|
||||
<div class='recaptcha-field mb-2'></div> |
||||
<input type='hidden' name='g-recaptcha-response' class='recaptcha-response' /> |
@ -0,0 +1,36 @@ |
||||
--- |
||||
|
||||
--- |
||||
|
||||
<script src='./captcha.js'></script> |
||||
|
||||
<script is:inline> |
||||
window.onCaptchaLoad = function () { |
||||
if (!window.grecaptcha) { |
||||
console.warn('window.grecaptcha is not defined'); |
||||
return; |
||||
} |
||||
|
||||
const recaptchaFields = document.querySelectorAll('.recaptcha-field'); |
||||
|
||||
// render recaptcha on fields |
||||
recaptchaFields.forEach((field) => { |
||||
// If captcha already rendered for this field |
||||
if (field.hasAttribute('data-recaptcha-id')) { |
||||
return; |
||||
} |
||||
|
||||
const renderedId = window.grecaptcha.render(field, { |
||||
sitekey: '6Ldn2YsjAAAAABlUxNxukAuDAUIuZIhO0hRVxzJW', |
||||
}); |
||||
|
||||
field.setAttribute('data-recaptcha-id', renderedId); |
||||
}); |
||||
}; |
||||
</script> |
||||
|
||||
<script |
||||
src='https://www.google.com/recaptcha/api.js?onload=onCaptchaLoad&render=explicit' |
||||
async |
||||
defer |
||||
></script> |
Loading…
Reference in new issue