first commit

This commit is contained in:
Michael 2020-09-26 15:22:19 +01:00
commit 008070e8d3

32
0cd.xyz-post.js Normal file
View File

@ -0,0 +1,32 @@
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"
}
}
}