Skip to content

Commit

Permalink
fix: make single attachment forms validatable using the Yii file vali…
Browse files Browse the repository at this point in the history
…dator
  • Loading branch information
nstCactus committed Jan 18, 2024
1 parent bb6ab42 commit 48deb41
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/SendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check failure on line 49 in src/controllers/SendController.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Property craft\contactform\models\Submission::$attachment (array<craft\web\UploadedFile|null>|null) does not accept craft\web\UploadedFile|null.
}
}

Expand Down

0 comments on commit 48deb41

Please sign in to comment.