Compare commits
No commits in common. "5c197f22993709118d20580562342f2bc3bf8b77" and "7ae47ee5903b55ede96239b857700b1d34112fc2" have entirely different histories.
5c197f2299
...
7ae47ee590
@ -1,45 +1,29 @@
|
|||||||
const contactFormAjaxUrl = '/php/contact_form.php';
|
const ajaxUrl = '../php/contact_form.php';
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
|
||||||
const contact_form = document.getElementsByClassName('content__contact_form')[0];
|
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();
|
|
||||||
formData.append('action', 'start_session');
|
|
||||||
fetch(contactFormAjaxUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
mode: 'same-origin',
|
|
||||||
body: formData,
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Response was not OK');
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(json => {
|
|
||||||
console.log(json);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Could not start the session:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function wtf_submitContactForm(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
const subject = document.getElementsByClassName('contact_form__subject')[0];
|
const subject = document.getElementsByClassName('contact_form__subject')[0];
|
||||||
const message = document.getElementsByClassName('contact_form__message')[0];
|
const message = document.getElementsByClassName('contact_form__message')[0];
|
||||||
const name = document.getElementsByClassName('contact_form__name')[0];
|
const name = document.getElementsByClassName('contact_form__name')[0];
|
||||||
const email = document.getElementsByClassName('contact_form__email')[0];
|
const email = document.getElementsByClassName('contact_form__email')[0];
|
||||||
const captcha = document.getElementsByClassName('contact_form__captcha')[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(event) {
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append('action', 'start_session');
|
||||||
|
fetch(ajaxUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
mode: 'same-origin',
|
||||||
|
body: formData,
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(json => {
|
||||||
|
console.log(json);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
contact_form.addEventListener('submit', function(event) {
|
||||||
|
event.preventDefault();
|
||||||
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');
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
@ -6,16 +6,17 @@ function sanitize_text(string $name, string $type) {
|
|||||||
'text' => FILTER_SANITIZE_SPECIAL_CHARS,
|
'text' => FILTER_SANITIZE_SPECIAL_CHARS,
|
||||||
'email' => FILTER_SANITIZE_EMAIL,
|
'email' => FILTER_SANITIZE_EMAIL,
|
||||||
);
|
);
|
||||||
$text = filter_var(trim($_POST[$name]), $filters[$type]);
|
$text = trim($text);
|
||||||
|
$text = filter_var($_POST[$name], $filters[$type]);
|
||||||
$text = stripslashes($text);
|
$text = stripslashes($text);
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare_message_body(string $message, string $name) {
|
function prepare_message_body($message) {
|
||||||
// Replace HTML-Entities with actual carriage returns and line feeds
|
// Replace HTML-Entities with actual carriage returns and line feeds
|
||||||
$message = str_replace(" ", "\r", $message);
|
$message = str_replace(" ", "\r", $message);
|
||||||
$message = str_replace(" ", "\n", $message);
|
$message = str_replace(" ", "\r", $message);
|
||||||
|
|
||||||
// Ensure line breaks via carriage return + line feed
|
// Ensure line breaks via carriage return + line feed
|
||||||
$message = str_replace("\r\n", "\n", $message);
|
$message = str_replace("\r\n", "\n", $message);
|
||||||
@ -33,30 +34,22 @@ function prepare_message_body(string $message, string $name) {
|
|||||||
* mail(): Braucht auf dem Server einen korrekt konfigurierten Mailserver
|
* mail(): Braucht auf dem Server einen korrekt konfigurierten Mailserver
|
||||||
* phpmailer: Bibliothek, der per Composer installiert wird. Tut ganz gut mit SMTP.
|
* phpmailer: Bibliothek, der per Composer installiert wird. Tut ganz gut mit SMTP.
|
||||||
*/
|
*/
|
||||||
function send_message_to_office(string $subject, string $message, string $name, string $email) {
|
function send_message_to_office($subject, $message, $name, $email) {
|
||||||
$returnPath = filter_var(getenv('WTF_RETURN_PATH'), FILTER_VALIDATE_EMAIL);
|
|
||||||
$to = filter_var(getenv('WTF_CONTACT_TO'), FILTER_VALIDATE_EMAIL);
|
|
||||||
|
|
||||||
if (!$returnPath || !$to) {
|
|
||||||
error_log('Address for "To" or "Return-Path" is invalid');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mail(
|
return mail(
|
||||||
$to,
|
getenv('WTF_CONTACT_TO'),
|
||||||
"=?UTF-8?B?" . base64_encode($subject) . "?=",
|
"=?UTF-8?B?" . base64_encode($subject) . "?=",
|
||||||
prepare_message_body($message, $name),
|
prepare_message_body($message),
|
||||||
array(
|
$additional_headers = array(
|
||||||
"From" => getenv('WTF_CONTACT_FROM'),
|
"From" => getenv('WTF_CONTACT_FROM'),
|
||||||
"Reply-To" => $email,
|
"Reply-To" => $email,
|
||||||
|
"Return-Path" => getenv('WTF_RETURN_PATH'),
|
||||||
"Content-Type" => "text/plain; charset=utf-8",
|
"Content-Type" => "text/plain; charset=utf-8",
|
||||||
"Content-Transfer-Encoding" => "base64",
|
"Content-Transfer-Encoding" => "base64",
|
||||||
),
|
),
|
||||||
"-f $returnPath"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_response(array $response_data) {
|
function send_response($response_data) {
|
||||||
$json = json_encode($response_data);
|
$json = json_encode($response_data);
|
||||||
if ($json === false) {
|
if ($json === false) {
|
||||||
// Avoid echo of empty string (which is invalid JSON), and
|
// Avoid echo of empty string (which is invalid JSON), and
|
||||||
|
@ -63,7 +63,7 @@ __ ____________________
|
|||||||
{% if 'manifest.json'|asseturl is defined -%}
|
{% if 'manifest.json'|asseturl is defined -%}
|
||||||
<link rel="manifest" href="{{ 'manifest.json'|asseturl }}">
|
<link rel="manifest" href="{{ 'manifest.json'|asseturl }}">
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{% if '/js/contact_form_toggle.js'|asseturl is defined and this.title == 'Kontakt' -%}
|
{% if '/js/contact_form_toggle.js'|asseturl is defined -%}
|
||||||
<script type="text/javascript" src="{{ '/js/contact_form_toggle.js'|asseturl }}"></script>
|
<script type="text/javascript" src="{{ '/js/contact_form_toggle.js'|asseturl }}"></script>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
</head>
|
</head>
|
||||||
@ -131,7 +131,7 @@ __ ____________________
|
|||||||
{%- if '/js/nav_toggle.js'|asseturl is defined -%}
|
{%- if '/js/nav_toggle.js'|asseturl is defined -%}
|
||||||
<script type="text/javascript" src="{{ '/js/nav_toggle.js'|asseturl }}"></script>
|
<script type="text/javascript" src="{{ '/js/nav_toggle.js'|asseturl }}"></script>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{% if '/js/contact_form_toggle.js'|asseturl is defined and this.title == 'Kontakt' -%}
|
{% if '/js/contact_form_toggle.js'|asseturl is defined -%}
|
||||||
<script type="text/javascript" src="{{ '/js/contact_form.js'|asseturl }}"></script>
|
<script type="text/javascript" src="{{ '/js/contact_form.js'|asseturl }}"></script>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user