#122_umlaute_kontaktformular #123

Merged
muli merged 2 commits from #122_umlaute_kontaktformular into #105_kontaktformular 2022-08-21 14:27:25 +02:00
Showing only changes of commit 4e7b22fde6 - Show all commits

View File

@ -1,11 +1,14 @@
<?php <?php
session_start(); session_start();
function sanitize_text(string $name) { function sanitize_text(string $name, string $type) {
$text = filter_var($_POST[$name], FILTER_SANITIZE_FULL_SPECIAL_CHARS); $filters = array(
'text' => FILTER_SANITIZE_SPECIAL_CHARS,
'email' => FILTER_SANITIZE_EMAIL,
);
$text = trim($text); $text = trim($text);
$text = filter_var($_POST[$name], $filters[$type]);
$text = stripslashes($text); $text = stripslashes($text);
$text = htmlspecialchars($text);
return $text; return $text;
} }
@ -75,10 +78,10 @@ function prepare_response() {
$response['errors'][] = 'Wir glauben Sie sind ein Bot.'; $response['errors'][] = 'Wir glauben Sie sind ein Bot.';
} }
if (!array_key_exists('errors', $response)) { if (!array_key_exists('errors', $response)) {
$subject = sanitize_text('subject'); $subject = sanitize_text('subject', 'text');
$message = sanitize_text('message'); $message = sanitize_text('message', 'text');
$name = sanitize_text('name'); $name = sanitize_text('name', 'text');
$email = sanitize_text('email'); $email = sanitize_text('email', 'email');
if (!send_message_to_office($subject, $message, $name, $email)) { if (!send_message_to_office($subject, $message, $name, $email)) {
$response['errors'][] = 'Ihre Nachricht konnte nicht übermittelt werden.'; $response['errors'][] = 'Ihre Nachricht konnte nicht übermittelt werden.';