Initial commit: Fat Kiss site — Hugo + Decap CMS
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// Fat Kiss — contact.js
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.getElementById('contactForm');
|
||||
if (!form) return;
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const btn = document.getElementById('submitBtn');
|
||||
const msg = document.getElementById('formMessage');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Sending…';
|
||||
|
||||
try {
|
||||
const fd = new FormData(form);
|
||||
const res = await fetch('/api/contact', {
|
||||
method: 'POST',
|
||||
headers: { 'Accept': 'application/json' },
|
||||
body: fd
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (res.ok && data.ok) {
|
||||
msg.innerHTML = '<div class="form-message form-message--success">Thank you — your note made it through. Fat Kiss will get back to you soon.</div>';
|
||||
form.reset();
|
||||
if (typeof turnstile !== 'undefined') turnstile.reset();
|
||||
} else {
|
||||
msg.innerHTML = '<div class="form-message form-message--error">' + (data.error || 'Something did not go through. Please try again in a moment.') + '</div>';
|
||||
}
|
||||
} catch (err) {
|
||||
msg.innerHTML = '<div class="form-message form-message--error">Something did not go through. Please try again in a moment.</div>';
|
||||
}
|
||||
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Send Message';
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user