This commit is contained in:
isUnknown 2025-01-26 14:44:21 +01:00
parent b1418ef194
commit 5c467757fe
4 changed files with 58 additions and 6 deletions

View file

@ -109,17 +109,22 @@ function slugify(str) {
function subscribe(event) {
event.preventDefault();
const email = document.querySelector("#subscribe-form input");
const emailInput = document.querySelector("#subscribe-form input");
if (email.value.toLowerCase().match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
if (emailInput.value.toLowerCase().match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
const header = {
method: "POST",
body: email.value,
body: JSON.stringify(emailInput.value),
};
fetch("/subscribe.json");
fetch("/subscribe.json", header)
.then((res) => res.json())
.then((data) => {
const formNode = emailInput.parentNode.parentNode;
formNode.outerHTML = "<p>" + data.message + "</p>";
});
} else {
email.value = "E-mail invalide. Recommencez.";
emailInput.value = "E-mail invalide. Recommencez.";
}
}