From 48deb41052110e9515c9fc92c598732d2d033380 Mon Sep 17 00:00:00 2001 From: Yohann Bianchi Date: Thu, 18 Jan 2024 12:36:11 +0100 Subject: [PATCH] fix: make single attachment forms validatable using the Yii file validator --- src/Mailer.php | 3 ++- src/controllers/SendController.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Mailer.php b/src/Mailer.php index 611a778..758a014 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -71,7 +71,8 @@ public function send(Submission $submission, bool $runValidation = true): bool if ($submission->attachment !== null) { $allowedFileTypes = Craft::$app->getConfig()->getGeneral()->allowedFileExtensions; - foreach ($submission->attachment as $attachment) { + $attachments = is_array($submission->attachment) ? $submission->attachment : [$submission->attachment]; + foreach ($attachments as $attachment) { if (!$attachment) { continue; } diff --git a/src/controllers/SendController.php b/src/controllers/SendController.php index cff7484..fe31a19 100644 --- a/src/controllers/SendController.php +++ b/src/controllers/SendController.php @@ -46,7 +46,7 @@ public function actionIndex() if (is_array($_FILES['attachment']['name'])) { $submission->attachment = UploadedFile::getInstancesByName('attachment'); } else { - $submission->attachment = [UploadedFile::getInstanceByName('attachment')]; + $submission->attachment = UploadedFile::getInstanceByName('attachment'); } }