feat: replace mzur/kirby-uniform with custom Kontaktformular implementation

Replaced the `mzur/kirby-uniform` dependency with a custom form handling solution. Updated `kontakt.php`, its backend controller, and corresponding email template for streamlined submission handling. Adjusted styles in `input.css` and integrated a honeypot field for spam prevention.
This commit is contained in:
2025-07-13 17:40:58 +02:00
parent 8fdb707178
commit 78789132a4
5 changed files with 111 additions and 60 deletions
+65 -27
View File
@@ -1,33 +1,71 @@
<?php
return function($kirby, $pages, $page) {
use Uniform\Form;
$alert = null;
return function ($kirby)
{
$form = new Form([
'email' => [
'rules' => ['required', 'email'],
'message' => 'Bitte geben Sie eine gültige E-Mail Adresse ein.',
],
'name' => [
'rules' => ['required'],
'message' => 'Bitte geben Sie Ihren Namen ein.',
],
'message' => [
'rules' => ['required'],
'message' => 'Bitte geben Sie eine Nachricht ein.',
],
]);
if ($kirby->request()->is('POST') && get('submit')) {
if ($kirby->request()->is('POST')) {
$form->emailAction([
'to' => [
'info@feigel.it'
],
'from' => 'webmaster@schachfreunde-badsteben.de',
'subject' => 'Kontaktanfrage über die Homepage der Schachfreunde Bad Steben',
])->done();
// check the honeypot
if (empty(get('website')) === false) {
go($page->url());
}
$data = [
'name' => get('name'),
'email' => get('email'),
'text' => get('text')
];
$rules = [
'name' => ['required', 'minLength' => 3],
'email' => ['required', 'email'],
'text' => ['required', 'minLength' => 3, 'maxLength' => 3000],
];
$messages = [
'name' => 'Bitte geben Sie einen Namen ein.',
'email' => 'Bitte geben Sie eine gültige E-Mail-Adresse ein.',
'text' => 'Bitte geben Sie einen Text ein, der zwischen 3 und 3000 Zeichen lang ist.'
];
// some of the data is invalid
if ($invalid = invalid($data, $rules, $messages)) {
$alert = $invalid;
// the data is fine, let's send the email
} else {
try {
$kirby->email([
'template' => 'email',
'from' => 'webmaster@schachfreunde-badsteben.de',
'replyTo' => $data['email'],
'to' => 'info@feigel.it',
'subject' => esc($data['name']) . ' hat eine Nachricht über das Kontaktformular gesendet',
'data' => [
'text' => esc($data['text']),
'sender' => esc($data['name'])
]
]);
} catch (Exception $error) {
if (option('debug')):
$alert['error'] = 'Beim Versenden ist ein Fehler aufgetreten: <strong>' . $error->getMessage() . '</strong>';
else:
$alert['error'] = 'Beim Versenden ist ein Fehler aufgetreten!';
endif;
}
// no exception occurred, let's send a success message
if (empty($alert) === true) {
$success = 'Ihre Nachricht wurde gesendet! Wir werden uns bald bei Ihnen melden.';
$data = [];
}
}
}
return compact('form');
};
return [
'alert' => $alert,
'data' => $data ?? false,
'success' => $success ?? false
];
};