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