57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
(() => {
|
|
const toggle = document.getElementById('mobileToggle');
|
|
const nav = document.getElementById('siteNav');
|
|
|
|
if (toggle && nav) {
|
|
toggle.addEventListener('click', () => {
|
|
const expanded = toggle.getAttribute('aria-expanded') === 'true';
|
|
toggle.setAttribute('aria-expanded', String(!expanded));
|
|
nav.classList.toggle('open');
|
|
});
|
|
|
|
nav.querySelectorAll('a').forEach((link) => {
|
|
link.addEventListener('click', () => {
|
|
toggle.setAttribute('aria-expanded', 'false');
|
|
nav.classList.remove('open');
|
|
});
|
|
});
|
|
}
|
|
|
|
const contactForm = document.getElementById('contactForm');
|
|
const status = document.getElementById('formStatus');
|
|
const endpoint = 'https://api.corben.world/forms/af90392e-9399-4778-9b80-9eed83580f1d/submit';
|
|
|
|
if (contactForm && status) {
|
|
contactForm.addEventListener('submit', async (event) => {
|
|
event.preventDefault();
|
|
|
|
if (!contactForm.checkValidity()) {
|
|
status.textContent = 'Please complete all required fields.';
|
|
status.className = 'form-status error';
|
|
contactForm.reportValidity();
|
|
return;
|
|
}
|
|
|
|
const payload = Object.fromEntries(new FormData(contactForm).entries());
|
|
status.textContent = 'Sending...';
|
|
status.className = 'form-status pending';
|
|
|
|
try {
|
|
const response = await fetch(endpoint, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload)
|
|
});
|
|
|
|
if (!response.ok) throw new Error('Submission failed');
|
|
|
|
status.textContent = 'Thank you. Your inquiry was submitted successfully.';
|
|
status.className = 'form-status success';
|
|
contactForm.reset();
|
|
} catch (error) {
|
|
status.textContent = 'Unable to submit right now. Please try again.';
|
|
status.className = 'form-status error';
|
|
}
|
|
});
|
|
}
|
|
})();
|