2022-06-16 13:02:42 +02:00
|
|
|
const ajaxUrl = 'https://spielwiese.wtf-eg.de/php/contact_form.php';
|
|
|
|
// const submit_button = document.getElementsByClassName('contact_form__submit_button')[0];
|
|
|
|
const contact_form = document.getElementsByClassName('content__contact_form')[0];
|
|
|
|
const message = document.getElementsByClassName('contact_form__message')[0];
|
|
|
|
const name = document.getElementsByClassName('contact_form__name')[0];
|
|
|
|
const email = document.getElementsByClassName('contact_form__email')[0];
|
|
|
|
const captcha = document.getElementsByClassName('contact_form__captcha')[0];
|
2022-06-16 16:41:24 +02:00
|
|
|
const now = (new Date().getTime/1000).toFixed();
|
2022-06-16 13:02:42 +02:00
|
|
|
|
|
|
|
contact_form.addEventListener('submit', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append('message', message.value);
|
|
|
|
formData.append('name', name.value);
|
|
|
|
formData.append('email', email.value);
|
2022-06-16 16:41:24 +02:00
|
|
|
formData.append('time_sent', now);
|
2022-06-16 13:02:42 +02:00
|
|
|
|
|
|
|
// If some bot entered some value, return.
|
|
|
|
if (typeof captcha.value == 'undefined') {
|
|
|
|
formData.append('captcha', 'Nudelsuppe');
|
|
|
|
} else {
|
|
|
|
console.log('bot detected');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(ajaxUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
mode:'same-origin',
|
|
|
|
body: formData,
|
|
|
|
})
|
|
|
|
.then(response => response.json())
|
2022-06-16 16:52:20 +02:00
|
|
|
.then(json => console.log(json))
|
|
|
|
.catch(error => console.log(error));
|
2022-06-16 13:02:42 +02:00
|
|
|
}, false);
|