Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
.DS_Store
vendor
/vendor
64 changes: 28 additions & 36 deletions resources/views/_panels/form.antlers.html
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
{{#

FORM EXAMPLE
+ REFERENCES HCAPTCHA SO REMOVE IF NOT NEEDED
+ REFERENCES TURNSTILE SO REMOVE IF NOT NEEDED OR USING SOMETHING ELSE

#}}
{{ form:create in="{choose_form|raw}" js="alpine:form" attr:x-ref="form" \x-data='{"h-captcha-response": ""}' }}
{{ form:create in="{choose_form|raw}" js="alpine:form" attr:x-ref="form" \x-data='{"cf-turnstile-response": ""}'}}

<div
x-cloak
x-data="formHandler({
beforeSubmit: (handler) => {
let widgetId;

if (! widgetId = handler.$el.closest('form')?.querySelector('[data-hcaptcha-widget-id]')?.getAttribute('data-hcaptcha-widget-id')) {
handler.submitWithoutInterception();
return;
x-data="formHandler({
onSuccess: (handler) => {
handler.$refs.form.classList.add('success');
handler.form.success = true;
setTimeout(() => { handler.$refs.form.classList.remove('success'); handler.form.success = false; }, 8000);
},
onError: (handler) => {
turnstile.reset()
}
})"
x-cloak
x-init="cfWidgetId = null;"
@turnstile-ready.window="
if (this.cfWidgetId) {
turnstile.remove(this.cfWidgetId);
}

let cfEl = $el.querySelector('.cf-turnstile');

this.cfWidgetId = turnstile.render(cfEl, {
sitekey: cfEl.getAttribute('data-sitekey'),
callback: function (token) {
form['cf-turnstile-response'] = token;
}

hcaptcha.execute(widgetId, { async: true })
.then(({ response, key }) => {
handler.form['h-captcha-response'] = response;
handler.submitWithoutInterception();
})
.catch(err => {
handler.form.errors._unspecified = 'Captcha error';
hcaptcha.reset(widgetId);
});
}
})"
@hcaptcha-ready.window="
let el;
if (el = $el.querySelector('.h-captcha')) {
let functionId = $id('hcaptchaCallBack');
el.setAttribute('data-callback', functionId);

window[functionId] = () => {
// empty function to prevent captcha doing anything
}

hcaptcha.render(el);
}
"
>
});
"
>

<p class="message" x-show="success">One of our team will be in touch as soon as possible.</p>

Expand Down
15 changes: 15 additions & 0 deletions resources/views/vendor/captcha/turnstile/head.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
turnstileReady = function() {
window.dispatchEvent(new CustomEvent('turnstile-ready'));
}

document.addEventListener('alpine:initialized', () => {
try {
window.turnstile?.ready(() => {
turnstileReady();
});
} catch (e) {
}
});
</script>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=turnstileReady&render=explicit" async></script>
Loading