37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
function alert() {
|
|
let alerts = {
|
|
"success": document.getElementById("success"),
|
|
"warning": document.getElementById("warning"),
|
|
"danger": document.getElementById("danger")
|
|
}
|
|
return alerts
|
|
}
|
|
|
|
async function post() {
|
|
var form = document.getElementById("form");
|
|
var alerts = alert();
|
|
for (const key in alerts) {
|
|
alerts[key].hidden=true
|
|
}
|
|
let response = await fetch("contact/form", {
|
|
method: "POST",
|
|
body: new FormData(form)
|
|
});
|
|
if (response.ok) {
|
|
alerts.success.hidden=false
|
|
alerts.success.textContent="Message sent, we'll get back to you as soon as possible"
|
|
form.reset();
|
|
} else {
|
|
if (response.status == 400) {
|
|
let json = await response.json();
|
|
if (json) {
|
|
alerts.danger.hidden=false
|
|
alerts.danger.textContent=json
|
|
}
|
|
} else {
|
|
alerts.warning.hidden=false
|
|
alerts.warning.textContent="Unable to send, please try again later"
|
|
}
|
|
}
|
|
}
|