From 1fee6b6475cf8fcfa5c5afed7ca5b9465e56af8e Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Tue, 1 Sep 2020 17:50:54 +0200 Subject: [PATCH] fix client side contact form onError --- static/contact.js | 21 ++++++++++----------- templates/contact.html | 10 ++++++---- templates/progress_window.html | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/static/contact.js b/static/contact.js index 1779a22..6dce774 100644 --- a/static/contact.js +++ b/static/contact.js @@ -1,4 +1,4 @@ -function submitForm(){ +function submitContactForm(){ /* show the waiting dialog */ dialog = document.getElementById("waiting-dialog") @@ -7,23 +7,17 @@ function submitForm(){ /* submit the form */ xhr = new XMLHttpRequest(); - xhr.open("POST", "/your/url/name.php"); - xhr.onload = + xhr.open("POST", "/contact-api"); + xhr.onload = formSubmitFinished formData = new FormData(document.getElementById("contact-form")); xhr.send(formData); - mainContainer = document.getElementById("main-container") - mainContainer.style.opacity = 0.5 - - window.location.href = "/thanks" - // after x seconds forward to thx - } function formSubmitFinished(event){ if(event.target.status != 200){ - showErrorMessage(); // blocking - setMainBackgroundOpacity(0.5) + showErrorMessage(event.target); // blocking + setMainBackgroundOpacity(1) }else{ window.location.href = "/thanks" } @@ -33,3 +27,8 @@ function setMainBackgroundOpacity(opacity){ mainContainer = document.getElementById("main-container") mainContainer.style.opacity = opacity } + +function showErrorMessage(target){ + console.log(target) + alert("Error: " + target.statusText) +} diff --git a/templates/contact.html b/templates/contact.html index 882854f..33dc35f 100644 --- a/templates/contact.html +++ b/templates/contact.html @@ -8,20 +8,22 @@ {% include 'head.html' %} + + {% include 'navbar.html' %} {% include 'progress_window.html' %} -
+

{{ conf['CONTACT_HEADLINE'] }}

-
+ +
@@ -57,7 +59,7 @@
- Send + Send
diff --git a/templates/progress_window.html b/templates/progress_window.html index 3598e71..5977e99 100644 --- a/templates/progress_window.html +++ b/templates/progress_window.html @@ -1,5 +1,5 @@ -