Compare commits
No commits in common. "3b14c0159158f402279b25145bbf1df1327ba104" and "42b9b3a62eeca1e600e5a8a71490c80177df88ed" have entirely different histories.
3b14c01591
...
42b9b3a62e
@ -1,45 +1,29 @@
|
|||||||
const contactFormAjaxUrl = '/php/contact_form.php';
|
const ajaxUrl = '../php/contact_form.php';
|
||||||
|
const contact_form = document.getElementsByClassName('content__contact_form')[0];
|
||||||
|
const subject = document.getElementsByClassName('contact_form__subject')[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];
|
||||||
|
const now = (new Date().getTime()/1000).toFixed();
|
||||||
|
const feedback = document.getElementsByClassName('contact_form__feedback')[0];
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
window.addEventListener('DOMContentLoaded', function(event) {
|
||||||
const contact_form = document.getElementsByClassName('content__contact_form')[0];
|
|
||||||
if (contact_form) {
|
|
||||||
contact_form.addEventListener('submit', wtf_submitContactForm, false);
|
|
||||||
wtf_startContactFormSession();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function wtf_startContactFormSession() {
|
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append('action', 'start_session');
|
formData.append('action', 'start_session');
|
||||||
fetch(contactFormAjaxUrl, {
|
fetch(ajaxUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'same-origin',
|
mode: 'same-origin',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => response.json())
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Response was not OK');
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(json => {
|
.then(json => {
|
||||||
console.log(json);
|
console.log(json);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
});
|
||||||
console.error('Could not start the session:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function wtf_submitContactForm(event) {
|
contact_form.addEventListener('submit', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const subject = document.getElementsByClassName('contact_form__subject')[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];
|
|
||||||
|
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append('action', 'handle_form');
|
formData.append('action', 'handle_form');
|
||||||
formData.append('subject', subject.value);
|
formData.append('subject', subject.value);
|
||||||
@ -55,14 +39,13 @@ function wtf_submitContactForm(event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(contactFormAjaxUrl, {
|
fetch(ajaxUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'same-origin',
|
mode: 'same-origin',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
const feedback = document.getElementsByClassName('contact_form__feedback')[0];
|
|
||||||
console.log(json);
|
console.log(json);
|
||||||
if (json.errors) {
|
if (json.errors) {
|
||||||
feedback.classList.remove('--success');
|
feedback.classList.remove('--success');
|
||||||
@ -92,4 +75,4 @@ function wtf_submitContactForm(event) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => console.log(error));
|
.catch(error => console.log(error));
|
||||||
}
|
}, false);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
/* Unhide contact form if JS is enabled */
|
/* Unhide contact form if JS is enabled */
|
||||||
window.addEventListener('DOMContentLoaded', (event) => {
|
window.addEventListener('DOMContentLoaded', (event) => {
|
||||||
const contact_form_wrapper = document.getElementsByClassName('content__contact_form_wrapper')[0];
|
const contact_form_wrapper = document.getElementsByClassName('content__contact_form_wrapper')[0];
|
||||||
if (contact_form_wrapper) {
|
contact_form_wrapper.style.setProperty('display', 'block');
|
||||||
contact_form_wrapper.style.setProperty('display', 'block');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user