templates/website/includes/captcha-form.html.twig line 1

Open in your IDE?
  1. {% set layoutRegister = (layout is defined and layout == 'register') ? true : false %}
  2. {% set wrapClass = (wrapClass is defined) ? wrapClass : 'cp' %}
  3. {% set inputId = (formName is defined) ? formName ~ '-captcha' : 'recaptcha' %}
  4. {% if isAppDomain %}
  5.     
  6.     {% set tokenDefault = getDefaultRecaptcha().defaultRecaptchaKeyV3 %}
  7.     <input type="hidden" name="g-recaptcha-response" id="{{ inputId }}">
  8.     <script src="https://www.google.com/recaptcha/api.js?render={{ tokenDefault }}"></script>
  9.     <script nonce="{{ nonceHash }}">
  10.         window['{{ formName }}Captcha'] = ()=> {
  11.                 grecaptcha.ready(function() {
  12.                       grecaptcha.execute("{{ tokenDefault }}", {action: 'submit'}).then(function(token) {
  13.                           var recaptcha = document.getElementById('{{ inputId }}');
  14.                         recaptcha.value = token;
  15.                       });
  16.                 });
  17.               }
  18.     </script>
  19. {# RECAPTCHA V3 #}
  20. {% elseif getConfig('recaptcha_key_v3') and getConfig('recaptcha_secret_v3') %}
  21.     <input type="hidden" name="g-recaptcha-response" id="{{ inputId }}">
  22.     <script src="https://www.google.com/recaptcha/api.js?render={{ getConfig('recaptcha_key_v3') }}"></script>
  23.     <script nonce="{{ nonceHash }}">
  24.               window['{{ formName }}Captcha'] = ()=> {
  25.             grecaptcha.ready(function() {
  26.                       grecaptcha.execute("{{ getConfig('recaptcha_key_v3') }}", {action: 'submit'}).then(function(token) {
  27.                           var recaptcha = document.getElementById('{{ inputId }}');
  28.                         recaptcha.value = token;
  29.                       });
  30.             });
  31.               }
  32.     </script>
  33. {# RECAPTCHA V2 #}
  34. {% elseif getConfig('recaptcha_key_v2') and getConfig('recaptcha_secret_v2') %}
  35.     <div class="{{ wrapClass }}">
  36.         <div class="g-recaptcha" data-sitekey="{{ getConfig('recaptcha_key_v2') }}"></div>
  37.     </div>
  38.     <script type="text/javascript" nonce="{{ nonceHash }}">
  39.         window['{{ scHash }}Captcha'] = ()=> {
  40.             let divRecaptcha = document.querySelectorAll('.g-recaptcha');
  41.             if(divRecaptcha.length > 0){
  42.                 for (var i = 0; i < divRecaptcha.length; i++) {
  43.                     if(divRecaptcha[i]){
  44.                             grecaptcha.render(divRecaptcha[i], {
  45.                                 'sitekey': divRecaptcha[i].getAttribute('data-sitekey')
  46.                             });
  47.                         }
  48.                     }
  49.             }
  50.         }
  51.     </script>
  52.     <script src="https://www.google.com/recaptcha/api.js?onload={{ scHash }}Captcha&render=explicit" async defer></script>
  53. {# EAD CAPTCHA #}
  54. {% else %}
  55.     <div class="{{ wrapClass }}">
  56.         <label for="captcha">Captcha&nbsp;<em>*</em></label>
  57.         {# <div class="{{ layoutRegister ? 'wrap' }} captcha"> #}
  58.         <div class="captcha-wrap wrap">
  59.             <input id="inputEadCaptcha" type="text" name="e-captcha" placeholder="{{ getLanguage('type_code', 'util') }}" required="required" class="wrap-error">
  60.             <input id="keyCaptcha" type="hidden" name="keyCaptcha" required="required" value="{{ keyCaptcha }}">
  61.             <img id="imgEadCaptcha" src="{{ path('eadCaptcha') }}?key={{ keyCaptcha }}">
  62.         </div>
  63.     </div>
  64. {% endif %}