-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinvisible.latte
64 lines (46 loc) · 1.39 KB
/
invisible.latte
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{define title}Invisible reCAPTCHA{/define}
{block styles}
<style>.form-group:nth-of-type(2) { display: none; }</style>
{/block}
{block content}
{import '../@form.latte'}
<div class="row">
<div class="col-lg-4 col-lg-offset-4">
{include bootstrap-form, form => invisibleForm}
</div>
</div>
{/block}
{block scripts}
<script src="{$basePath}/assets/vendor/nette-forms/src/assets/netteForms.min.js"></script>
<script>
(function (window, $) {
// map of <htmlID>: <widget/client ID>
var clientIDs = {};
window['g_onRecaptchaLoad'] = function () {
$('.g-recaptcha').each(function () {
var el = $(this);
clientIDs[this.id] = grecaptcha.render(this, {
size: 'invisible',
badge: 'inline',
callback: function (token) {
el.closest('form').off('submit.recaptcha').trigger('submit');
}
}, true);
});
$(function () {
$('form').on('submit.recaptcha', function (event) {
event.preventDefault();
var form = $(this);
if (Nette.validateForm(this, true)) {
// execute only reCAPTCHAs in submitted form
$('.g-recaptcha', form).each(function () {
grecaptcha.execute(clientIDs[this.id]);
});
}
});
});
};
})(window, window.jQuery);
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=g_onRecaptchaLoad&render=explicit" async defer></script>
{/block}