53 lines
2.3 KiB
JavaScript
53 lines
2.3 KiB
JavaScript
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Contact form validation
|
|
const contactForm = document.getElementById('contactForm');
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', function (event) {
|
|
if (!contactForm.checkValidity()) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
contactForm.classList.add('was-validated');
|
|
}, false);
|
|
}
|
|
|
|
// Toast notification for form submission status
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const status = urlParams.get('status');
|
|
if (status) {
|
|
const toastContainer = document.getElementById('toast-container');
|
|
let toastHTML = '';
|
|
if (status === 'success') {
|
|
toastHTML = `
|
|
<div class="toast align-items-center text-white bg-success border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="d-flex">
|
|
<div class="toast-body">
|
|
Message sent successfully! We will get back to you shortly.
|
|
</div>
|
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
} else if (status === 'error') {
|
|
const msg = urlParams.get('msg') || 'An unexpected error occurred.';
|
|
toastHTML = `
|
|
<div class="toast align-items-center text-white bg-danger border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="d-flex">
|
|
<div class="toast-body">
|
|
<strong>Error:</strong> ${decodeURIComponent(msg)}
|
|
</div>
|
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
if(toastContainer) {
|
|
toastContainer.innerHTML = toastHTML;
|
|
const toastElement = toastContainer.querySelector('.toast');
|
|
const toast = new bootstrap.Toast(toastElement, { delay: 5000 });
|
|
toast.show();
|
|
}
|
|
}
|
|
});
|