I have already created a working form with Uniform. Now my client would like to send files with this form as well.
The form controller is structured as below:
<?php
use Uniform\Form;
return function ($kirby) {
$form = new Form([
'bewerbungals' => [
'rules' => ['required'],
'message' => 'Geben Sie die Stelle ein, für die Sie sich bewerben',
],
'name' => [
'rules' => ['required'],
'message' => 'Geben Sie Ihren Namen ein',
],
'strasse' => [
'rules' => ['required'],
'message' => 'Geben Sie Ihre Strasse und Hausnummer ein',
],
'plzort' => [
'rules' => ['required'],
'message' => 'Geben Sie Ihren Wohnort und Ihre Postleitzahl ein',
],
'email' => [
'rules' => ['required', 'email'],
'message' => 'Geben Sie Ihre Emailadresse ein',
],
'filefield' => [
'rules' => [
'mime' => ['application/pdf'],
'filesize' => 5000,
],
'message' => [
'Bitte senden Sie ausschliesslich PDFs.',
'Die gesendeten Dateien müssen kleiner als 5MB sein.',
],
],
'datenschutz' => [
'rules' => ['required'],
'message' => 'Markieren Sie die Checkbox für die Datenschutzerklärung',
],
]);
$attachments = [];
// Which command should be used here?
$attachments[] = ???['filefield'];
if ($kirby->request()->is('POST')) {
$form->emailAction([
'to' => 'misterx@t-online.de',
'from' => 'kontakt@misterx.de',
'subject' => 'Neue Bewerbung von {{email}}',
'attachments' => $attachments,
]);
}
return compact('form');
};
How can I convert the field ‘filefield’, which contains the files selected in the form, into an array?
Do I need another controller to do that?