40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function () {
|
|
const contactForm = document.getElementById('contact-form');
|
|
const contactToast = new bootstrap.Toast(document.getElementById('contact-toast'));
|
|
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(contactForm);
|
|
|
|
fetch('contact_handler.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const toastBody = document.querySelector('#contact-toast .toast-body');
|
|
if (data.success) {
|
|
toastBody.textContent = 'Thank you for your message! We will get back to you shortly.';
|
|
contactForm.reset();
|
|
} else {
|
|
toastBody.textContent = data.error || 'An error occurred. Please try again.';
|
|
}
|
|
contactToast.show();
|
|
})
|
|
.catch(error => {
|
|
const toastBody = document.querySelector('#contact-toast .toast-body');
|
|
toastBody.textContent = 'A network error occurred. Please try again.';
|
|
contactToast.show();
|
|
});
|
|
});
|
|
}
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
if (urlParams.has('error')) {
|
|
const loginModal = new bootstrap.Modal(document.getElementById('loginModal'));
|
|
loginModal.show();
|
|
}
|
|
});
|