/
ewz_recaptcha_widget.html.twig
29 lines (25 loc) · 1.29 KB
/
ewz_recaptcha_widget.html.twig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{% block ewz_recaptcha_widget %}
{% apply spaceless %}
{% if form.vars.ewz_recaptcha_enabled %}
<script src="{{ form.vars.ewz_recaptcha_api_uri }}?render={{ form.vars.public_key }}"></script>
{% if form.vars.ewz_recaptcha_hide_badge %}
<link rel="stylesheet" href="{{ asset('/bundles/ewzrecaptcha/css/recaptcha.css') }}">
{% endif %}
{{ form_widget(form) }}
<script{% if form.vars.script_nonce_csp is defined and form.vars.script_nonce_csp is not same as('') %} nonce="{{ form.vars.script_nonce_csp }}"{% endif %}>
var grecaptchaInput = document.getElementById('{{ id }}');
grecaptchaInput.value = ''; // Always reset the value to get a brand new challenge
var grecaptchaForm = grecaptchaInput.form;
grecaptchaForm.addEventListener('submit', function (e) {
e.preventDefault();
grecaptcha.ready(function () {
grecaptcha.execute('{{ form.vars.public_key }}', { action: '{{ form.vars.action_name|default(constant('EWZ\\Bundle\\RecaptchaBundle\\Form\\Type\\EWZRecaptchaV3Type::DEFAULT_ACTION_NAME')) }}' }).then(function (token) {
grecaptchaInput.value = token;
HTMLFormElement.prototype.submit.call(grecaptchaForm);
});
});
}, false);
</script>
{% endif %}
{% endapply %}
{% endblock %}