X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2FcontactForm.js;fp=public%2Fjavascripts%2FcontactForm.js;h=0c4fea3ada2d06bb302f2def5edd1f27a847b98d;hb=298c42e63ae321526693e9ce418c4113af36e025;hp=0000000000000000000000000000000000000000;hpb=067c675b75072c496f9665c4bf801cdc3d40398d;p=vchess.git diff --git a/public/javascripts/contactForm.js b/public/javascripts/contactForm.js new file mode 100644 index 00000000..0c4fea3a --- /dev/null +++ b/public/javascripts/contactForm.js @@ -0,0 +1,31 @@ +// Note: not using Vue, but would be possible +function trySendMessage() +{ + let email = document.getElementById("userEmail"); + let subject = document.getElementById("mailSubject"); + let content = document.getElementById("mailContent"); + if (!email.value.match(/^[^@]+@[^@]+\.[^@]+$/)) + return alert("Bad email"); + if (content.value.trim().length == 0) + return alert("Empty message"); + if (subject.value.trim().length == 0 && !confirm("No subject. Send anyway?")) + return; + + // Message sending: + ajax( + "/messages", + "POST", + { + email: email.value, + subject: subject.value, + content: content.value, + }, + () => { + subject.value = ""; + content.value = ""; + let emailSent = document.getElementById("emailSent"); + emailSent.style.display = "inline-block"; + setTimeout(() => { emailSent.style.display = "none"; }, 2000); + } + ); +}