{% set layoutRegister = (layout is defined and layout == 'register') ? true : false %}
{% set wrapClass = (wrapClass is defined) ? wrapClass : 'cp' %}
{% set inputId = (formName is defined) ? formName ~ '-captcha' : 'recaptcha' %}
{# --- !!! --- #}
{% if isAppDomain %}
{% set tokenDefault = getDefaultRecaptcha().defaultRecaptchaKeyV3 %}
<input type="hidden" name="g-recaptcha-response" id="{{ inputId }}">
<script src="https://www.google.com/recaptcha/api.js?render={{ tokenDefault }}"></script>
<script nonce="{{ nonceHash }}">
window['{{ formName }}Captcha'] = ()=> {
grecaptcha.ready(function() {
grecaptcha.execute("{{ tokenDefault }}", {action: 'submit'}).then(function(token) {
var recaptcha = document.getElementById('{{ inputId }}');
recaptcha.value = token;
});
});
}
</script>
{# RECAPTCHA V3 #}
{% elseif getConfig('recaptcha_key_v3') and getConfig('recaptcha_secret_v3') %}
<input type="hidden" name="g-recaptcha-response" id="{{ inputId }}">
<script src="https://www.google.com/recaptcha/api.js?render={{ getConfig('recaptcha_key_v3') }}"></script>
<script nonce="{{ nonceHash }}">
window['{{ formName }}Captcha'] = ()=> {
grecaptcha.ready(function() {
grecaptcha.execute("{{ getConfig('recaptcha_key_v3') }}", {action: 'submit'}).then(function(token) {
var recaptcha = document.getElementById('{{ inputId }}');
recaptcha.value = token;
});
});
}
</script>
{# RECAPTCHA V2 #}
{% elseif getConfig('recaptcha_key_v2') and getConfig('recaptcha_secret_v2') %}
<div class="{{ wrapClass }}">
<div class="g-recaptcha" data-sitekey="{{ getConfig('recaptcha_key_v2') }}"></div>
</div>
<script type="text/javascript" nonce="{{ nonceHash }}">
window['{{ scHash }}Captcha'] = ()=> {
let divRecaptcha = document.querySelectorAll('.g-recaptcha');
if(divRecaptcha.length > 0){
for (var i = 0; i < divRecaptcha.length; i++) {
if(divRecaptcha[i]){
grecaptcha.render(divRecaptcha[i], {
'sitekey': divRecaptcha[i].getAttribute('data-sitekey')
});
}
}
}
}
</script>
<script src="https://www.google.com/recaptcha/api.js?onload={{ scHash }}Captcha&render=explicit" async defer></script>
{# EAD CAPTCHA #}
{% else %}
{% endif %}