fix #21
This commit is contained in:
parent
b1418ef194
commit
5c467757fe
4 changed files with 58 additions and 6 deletions
|
|
@ -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.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue