mirror of
https://github.com/FAUSheppy/oh-my-nemesis
synced 2025-12-10 00:28:32 +01:00
Initial (reset)
This commit is contained in:
48
static/contact.js
Normal file
48
static/contact.js
Normal file
@@ -0,0 +1,48 @@
|
||||
function submitContactForm(){
|
||||
|
||||
/* check input fields */
|
||||
mailField = document.getElementById("email")
|
||||
messageField = document.getElementById("message")
|
||||
|
||||
if(mailField.value == ""){
|
||||
alert("Bitte geben Sie einen Kontakt an unter dem wir Sie erreichen können!")
|
||||
return
|
||||
}
|
||||
|
||||
if(messageField.value == ""){
|
||||
alert("Nachricht ist leer!")
|
||||
return
|
||||
}
|
||||
|
||||
/* show the waiting dialog */
|
||||
dialog = document.getElementById("waiting-dialog")
|
||||
dialog.style.disply = "block"
|
||||
setMainBackgroundOpacity(0.5)
|
||||
|
||||
/* submit the form */
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/contact-api");
|
||||
xhr.onload = formSubmitFinished
|
||||
formData = new FormData(document.getElementById("contact-form"));
|
||||
xhr.send(formData);
|
||||
|
||||
}
|
||||
|
||||
function formSubmitFinished(event){
|
||||
if(event.target.status < 200 || event.target.status >= 300){
|
||||
showErrorMessage(event.target); // blocking
|
||||
setMainBackgroundOpacity(1)
|
||||
}else{
|
||||
window.location.href = "/thanks"
|
||||
}
|
||||
}
|
||||
|
||||
function setMainBackgroundOpacity(opacity){
|
||||
mainContainer = document.getElementById("main-container")
|
||||
mainContainer.style.opacity = opacity
|
||||
}
|
||||
|
||||
function showErrorMessage(target){
|
||||
console.log(target)
|
||||
alert("Error: " + target.statusText)
|
||||
}
|
||||
Reference in New Issue
Block a user