mirror of
https://github.com/FAUSheppy/flask-json-dream-website
synced 2025-12-06 08:11:35 +01:00
fix client side contact form onError
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user