commit 008070e8d3c50aaf28339abfcfc85c1ff498e643 Author: Michael Date: Sat Sep 26 15:22:19 2020 +0100 first commit diff --git a/0cd.xyz-post.js b/0cd.xyz-post.js new file mode 100644 index 0000000..122c111 --- /dev/null +++ b/0cd.xyz-post.js @@ -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" + } + } +}