const baseForm = document.getElementById('base-form')
if (baseForm) {
baseForm.addEventListener('submit', e => {
e.preventDefault();
handleSubmit(baseForm);
})
}
const handleSubmit = form => {
const data = new FormData(form)
data.append('form-name', 'baseform');
fetch("/", {
method: "POST",
body: data,
})
.then(() => {
var messageDiv = document.getElementById('form-success');
displayMessage(messageDiv);
})
.catch((error) => {
var messageDiv = document.getElementById('form-warning');
displayMessage(messageDiv);
console.log(error);
}
);
function displayMessage(messageDiv){
messageDiv.classList.remove('hidden');
messageDiv.setAttribute('role', 'alert');
setTimeout(function() {
messageDiv.style.opacity = 1;
}, 1000)
setTimeout(function() {
messageDiv.style.opacity = 0;
setTimeout(function() {
messageDiv.classList.add('hidden');
messageDiv.removeAttribute('role');
}, 1000)
}, 6000);
};
};