pastebin/0cd.xyz-post.js
2020-09-26 15:22:19 +01:00

33 lines
1.1 KiB
JavaScript

async function post() {
let formData = new FormData();
var success = document.getElementById("success")
var warning = document.getElementById("warning")
var danger = document.getElementById("danger")
success.hidden=true
warning.hidden=true
danger.hidden=true
formData.append("email", document.getElementById("email").value);
formData.append("message", document.getElementById("message").value);
let response = await fetch("contact/form", {
method: "POST",
body: formData
});
if (response.ok) {
success.hidden=false
success.textContent="Message sent, we'll get back to you as soon as possible"
document.getElementById("email").value=""
document.getElementById("message").value="";
} else {
if (response.status == 400) {
let json = await response.json();
if (json) {
danger.hidden=false
danger.textContent=json
}
} else {
warning.hidden=false
warning.textContent="Unable to send, please try again later"
}
}
}