Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('contactForm');
const popUp = document.querySelector('.pop-up');
const popUpTitle = document.querySelector('.pop-up_container_title');
const popUpText = document.querySelector('.pop-up_container_text');
const popUpIcon = document.querySelector('.check-icon');
const closeBtn = document.querySelector('.close-modal');
const loader = document.querySelector('.loader');
let translations = {};
let lang = localStorage.getItem('selectedLanguage') || 'en';
function loadTranslations(language) {
return fetch(`./js/translations/${language}.json`)
.then(res => res.json())
.then(data => {
translations = data;
lang = language;
});
}
loadTranslations(lang);
document.addEventListener('languageChanged', (e) => {
const newLang = e.detail.lang;
loadTranslations(newLang);
});
form.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(form);
if (loader) loader.style.display = 'flex';
fetch('handle-mail.php', {
method: 'POST',
body: formData
})
.then(res => res.json())
.then(data => {
if (data.success) {
popUpTitle.textContent = translations.modalTitle || 'Success';
popUpText.textContent = translations.modalText || 'Your message has been sent successfully!';
popUpIcon.classList.remove('fa-circle-xmark');
popUpIcon.classList.add('fa-circle-check');
popUpIcon.style.color = '#4BB543';
} else {
popUpTitle.textContent = translations.modalErrorTitle || 'Error';
popUpText.textContent = translations.modalErrorText || 'Your message could not be sent. Please try again later.';
popUpIcon.classList.remove('fa-circle-check');
popUpIcon.classList.add('fa-circle-xmark');
popUpIcon.style.color = '#E74C3C';
}
popUp.style.display = 'flex';
})
.catch(() => {
popUpTitle.textContent = translations.modalErrorTitle || 'Error';
popUpText.textContent = translations.modalErrorText || 'Your message could not be sent. Please try again later.';
popUpIcon.classList.remove('fa-circle-check');
popUpIcon.classList.add('fa-circle-xmark');
popUpIcon.style.color = '#E74C3C';
popUp.style.display = 'flex';
})
.finally(() => {
if (loader) loader.style.display = 'none';
});
});
closeBtn.addEventListener('click', () => {
popUp.style.display = 'none';
});
});