handle undert twelve

This commit is contained in:
Julian
2022-02-18 12:51:32 +01:00
parent b754ad3075
commit 3facf06568
11 changed files with 83 additions and 39 deletions

View File

@@ -371,17 +371,59 @@
}());
document.getElementById("finalSubmit").addEventListener("click", async function () {
var form = document.getElementById("attendForm");
const formattedFormData = new FormData(form);
//formattedFormData.append('property', 'value');
const response = await fetch('email.php',{
method: 'POST',
body: formattedFormData
});
const data = await response.text();
//This should later print out the values submitted through the form
console.log(data);
document.getElementById("js-submitbtn").addEventListener("click", async function () {
event.preventDefault();
let inputs = document.querySelectorAll('.js-form-input');
console.log(inputs);
let from = inputs[0].value;
let message = inputs[1].value;
if(StringLengthLT2(from))
{
SubmitError("Name too short!");
return;
}
if(StringLengthLT2(message))
{
SubmitError("message too short!");
return;
}
let contact = {
from: from,
email: "none",
message: message,
};
const response = await fetch("https://rismer.de:9999/contact", {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
//credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(contact) // body data type must match "Content-Type" header
}).catch(function (timeout) { SubmitError("API error. Call the phone number."); });
console.log("Request: " + JSON.stringify(contact));
if(response.ok)
{
let jsonResponse = await response.json();
console.log("Response: " + jsonResponse);
SubmitSuccess();
}
else
{
SubmitError();
}
});
// document.getElementById("js-submitbtn").addEventListener("click", async function () {
@@ -527,8 +569,8 @@ document.getElementById("finalSubmit").addEventListener("click", async function
}
async function SubmitSuccess() {
let title = 'Teilgenommen';
let text = "Wir freuen uns auf euch!";
let title = 'Rückgemeldet';
let text = "Nun gibt es kein zurück mehr!";
title = await translator.getTranslationByKey(document.documentElement.lang,"success_title");
text = await translator.getTranslationByKey(document.documentElement.lang,"success_text");
@@ -543,8 +585,6 @@ document.getElementById("finalSubmit").addEventListener("click", async function
//document.querySelector('#myfrm').submit(); // manully submit
}).catch(function (timeout) { });
document.getElementById("attentant-container").remove();
document.getElementById("overnight-div").remove();
document.getElementById("js-submitbtn").disabled = 'true';
document.getElementById("js-submitbtn").textContent = await translator.getTranslationByKey(document.documentElement.lang,"already_participating");
return;