diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c8c4ba..9f173c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added Craft 5 compatibility. - Added a missing Dutch translation. ([#257](https://github.com/craftcms/contact-form/issues/257)) +- Fixed a bug where it wasn’t possible to upload a single file with the `attachment` param. ([#254](https://github.com/craftcms/contact-form/issues/254)) ## 3.0.1 - 2023-03-16 @@ -22,7 +23,7 @@ ## 2.5.2 - 2023-03-16 -- Added translations for for `Email` and `Name`. ([#235](https://github.com/craftcms/contact-form/issues/235)) +- Added translations for `Email` and `Name`. ([#235](https://github.com/craftcms/contact-form/issues/235)) ## 2.5.1 - 2022-05-02 diff --git a/README.md b/README.md index 5e2ba16..48c6aca 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ return [ ### Overriding plugin settings -If you create a [config file](https://craftcms.com/docs/4.x/config/general.html) in your `config/` folder called `contact-form.php`, you can override +If you create a [config file](https://craftcms.com/docs/4.x/config/) in your `config/` folder called `contact-form.php`, you can override the plugin’s settings in the Control Panel. Since that config file is fully [multi-environment](https://craftcms.com/docs/4.x/config/#multi-environment-configs) aware, this is a handy way to have different settings across multiple environments. diff --git a/src/Mailer.php b/src/Mailer.php index 611a778..48f2a84 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -71,6 +71,10 @@ public function send(Submission $submission, bool $runValidation = true): bool if ($submission->attachment !== null) { $allowedFileTypes = Craft::$app->getConfig()->getGeneral()->allowedFileExtensions; + if (!is_array($submission->attachment)) { + $submission->attachment = [$submission->attachment]; + } + foreach ($submission->attachment 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'); } } diff --git a/src/models/Submission.php b/src/models/Submission.php index 750b85d..2384974 100644 --- a/src/models/Submission.php +++ b/src/models/Submission.php @@ -39,8 +39,8 @@ class Submission extends Model public $message; /** - * @var UploadedFile[]|null[]|null - * @phpstan-var array|null + * @var UploadedFile|UploadedFile[]|null[]|null + * @phpstan-var UploadedFile|array|null */ public $attachment;