Hey there,
maybe it’s more a question about php in general than Kirby, but I have no idea how I get and send data from my radio and select option of the contact form to my email.
I only found this on the www. “https://kirby-uniform.readthedocs.io/en/latest/examples/extended/” and think it should go into the right direction?
The “input type= text fields” are working fine and I receive the written data in my e-mail. Thank you for the cookbooks on your homepage! Without I wouldn’t have known where to start ( I’m a noob in php and stuff like java…).
HELP
Here comes my troublemaker-code that is wrong right now:
From my snippet I’ve used in the article.php (name: contacttagesfahrten.php)
<div class="field">
<label for="zustieg">
<h6>Zustieg<abbr title="required">*</abbr></h6>
</label>
<p>
<input type="Radio" name="zustieg" value="eins" required> Zustieg 1</input>
<input type="Radio" name="zustieg" value="zwei" required> Zustieg 2</input>
<input type="Radio" name="zustieg" value="drei" required> Zustieg 3</input>
<?= isset($alert['zustieg']) ? '<span class="alert error">' . html($alert['zustieg']) . '</span>' : '' ?>
</p>
</div><hr />
<div class="field">
<label for="reisebuero">
<h6>Reisebüro<abbr title="required">*</abbr></h6>
</label>
<select name="reisebuero" size="" required>
<option value="">Ihr Reisebüro</option>
<optgroup label="Bad Schandau" class="reisebuerostadt">
<option value="1">Reisebüro Adresse 1</option>
</optgroup>
<optgroup label="Boxdorf" class="reisebuerostadt">
<option value="2">Reisebüro Adresse 2</option>
</optgroup>
<optgroup label="Coswig" class="reisebuerostadt">
<option value="3">Reisebüro Adresse 3</option>
</optgroup>
<?= isset($alert['reisebuero']) ? '<span class="alert error">' . html($alert['reisebuero']) . '</span>' : '' ?>
</select>
</div>
My controller:
article.php
<?php
return function($kirby, $pages, $page) {
// get all subpages
$subpages = $page->children()->listed();
// pass $articles and $pagination to the template
$alert = null;
if($page->reisetermin()->isempty()) {
if($kirby->request()->is('POST') && get('submit')) {
// check the honeypot
if(empty(get('website')) === false) {
go($page->url());
exit;
}
$data = [
'reise' => get('reise'),
'termin' => get('termin'),
'personenanzahl' => get('personenanzahl'),
'personen' => get('personen'),
'zustieg' => get('zustieg'. 'checked'),
'reisebuero' => get('reisebuero'),
'name' => get('name'),
'strasse' => get('strasse'),
'plzort' => get('plzort'),
'telefon' => get('telefon'),
'email' => get('email'),
'text' => get('text'),
'dsgvo' => get('dsgvo'),
'formblatt' => get('formblatt')
];
$rules = [
'reise' => ['min' => 3],
'termin' => ['min' => 3],
'personenanzahl' => ['required', 'min' => 1],
'personen' => ['required', 'min' => 3, 'max' => 3000],
'zustieg' => ['checked'],
'reisebuero' => ['checked'],
'name' => ['required', 'min' => 3],
'strasse' => ['required', 'min' => 3],
'plzort' => ['required', 'min' => 5],
'telefon' => ['required', 'min' => 3],
'email' => ['required', 'email'],
'formblatt' => ['required',],
'dsgvo' => ['required',]
];
$messages = [
'reise' => 'Bitte geben Sie den Namen der Reise ein',
'termin' => 'Bitte geben Sie das Reisedatum ein',
'personenanzahl' => 'Bitte geben Sie die Personenanzahl ein',
'personen' => 'Bitte geben Sie die Personen an',
'zustieg' => 'Bitte wählen Sie eine Option aus',
'reisebuero' => 'Bitte wählen Sie ein Reisebüro aus',
'name' => 'Bitte geben Sie Ihren vollen Namen ein',
'email' => 'Bitte geben Sie eine gültige E-Mail-Adresse ein',
'strasse' => 'Bitte geben Sie Ihre Straße ein',
'plzort' => 'Bitte geben Sie Ihre PLZ ein',
'telefon' => 'Bitte geben Sie Ihre Telefonnummer an'
];
// 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' => 'emailtagesfahrten',
'from' => esc($kirby->site()->email()),
'replyTo' => $data['email'],
'to' => esc($kirby->site()->email()),
'subject' => esc($data['name']) . ' hat Ihnen eine Buchungsanfrage für eine Tagesfahrt gesendet',
'data' => [
'reise' => esc($data['reise']),
'termin' => esc($data['termin']),
'personenanzahl' => esc($data['personenanzahl']),
'personen' => esc($data['personen']),
'zustieg' => esc($data['zustieg']),
'reisebuero' => esc($data['reisebuero']),
'text' => esc($data['text']),
'strasse' => esc($data['strasse']),
'plzort' => esc($data['plzort']),
'telefon' => esc($data['telefon']),
'email' => esc($data['email']),
'sender' => esc($data['name'])
]
]);
} catch (Exception $error) {
$alert['error'] = "Die Nachricht konnte nicht gesendet werden";
}
// no exception occured, let's send a success message
if (empty($alert) === true) {
$success = 'Ihre Nachricht wurde gesendet. Vielen Dank, wir melden uns schnellstmöglich bei Ihnen zurück';
$data = [];
}
}
} }
return [
'alert' => $alert,
'data' => $data ?? false,
'success' => $success ?? false
];
};
So may anybody give me a hint/ example, how I have to write “if that value is selected send me this text and if the second value is selected send me this text, please…”? Is it possible to solve it just in the controller and template.php and the email.php? Or do I have to do other stuff somewhere else?
Thank you!
Best regards,
Isabelle