derv-net/public/index.js

31 lines
697 B
JavaScript
Raw Permalink Normal View History

2025-02-25 19:47:28 -05:00
async function formClick(ev) {
ev.preventDefault();
let { target } = ev;
let fData = new FormData(target);
2025-02-26 20:17:33 -05:00
for (let file of target.querySelectorAll('.form-input')) {
2025-02-25 19:47:28 -05:00
file.value = null;
2025-02-26 20:17:33 -05:00
file.textContent = '';
}
2025-02-25 19:47:28 -05:00
let fetched = await fetch(target.action, {
'method': 'POST',
'body': fData
});
let json = await fetched.json();
target.querySelector('.form-message').textContent = json.message;
if (json.redirect && json.success) {
setTimeout(function () {
window.location.href = json.redirect;
}, 2000);
}
}
window.onload = function () {
document.addEventListener('submit', formClick);
}