fix client side contact form onError

This commit is contained in:
Yannik Schmidt
2020-09-01 17:50:54 +02:00
parent 430e0f60aa
commit 1fee6b6475
3 changed files with 17 additions and 16 deletions

View File

@@ -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)
}