Skip to content

Commit

Permalink
Add new article and implement simple spam protection for contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-cologne committed Nov 11, 2018
1 parent c5191e7 commit a62f3f6
Show file tree
Hide file tree
Showing 4 changed files with 653 additions and 11 deletions.
11 changes: 8 additions & 3 deletions _app/php/functions.php
Expand Up @@ -9,12 +9,16 @@ function processContactForm(array $form_data) {
$form_data[$key] = clean($value);
}

['name' => $name, 'email' => $email, 'subject' => $subject, 'message' => $message] = $form_data;
['name' => $name, 'email' => $email, 'subject' => $subject, 'message' => $message, 'spam_check' => $spam_check] = $form_data;

if ( empty($name) && empty($email) && empty($subject) && empty($message) ) {
if ( empty($name) && empty($email) && empty($subject) && empty($message) && empty($spam_check) ) {
return ERR_HTML_START . 'Du hast nicht alle Felder ausgefüllt. Bitte versuche es nochmal!' . ERR_HTML_END;
}

if ($spam_check != '8') {
return ERR_HTML_START . 'Du hast die untenstehende Frage zur Spam-Bekämpfung leider falsch beantwortet. Bitte versuche es nochmal!' . ERR_HTML_END;
}

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return ERR_HTML_START . 'Du hast keine gültige E-Mail-Adresse angegeben. Bitte versuche es nochmal!' . ERR_HTML_END;
}
Expand All @@ -27,6 +31,7 @@ function processContactForm(array $form_data) {
}

header('Location: danke.html');
exit();
}

function clean(string $value) {
Expand All @@ -40,4 +45,4 @@ function sendMail(string $name, string $email, string $subject, string $message)

return $mail->sent;
}
?>
?>

0 comments on commit a62f3f6

Please sign in to comment.