handle undert twelve
This commit is contained in:
70
js/main.js
70
js/main.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user