You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `FileProcessorFormField` is used to upload files to the server via the file processor.
587
587
588
-
By default, `FileProcessorFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the appropriate array of fileIDs to the `$parameters` array directly, using the object property as the array key.
589
-
If `isSingleFileUpload()` is enabled, the value will be added to the data sub-array of the parameters array and the value can be null.
590
-
591
588
The checks for the correct file size or extension don't take place in the FormField, this must be defined in the `IFileProcessor`.
592
589
593
590
__The field supports other settings:__
@@ -596,7 +593,10 @@ __The field supports other settings:__
596
593
-`context(array $context)` and `getContext()` can be used to set and get the context of the file processor.
597
594
-`singleFileUpload($singleFileUpload = true)` and `isSingleFileUpload()` can be used to set and check if only one file can be uploaded.
598
595
599
-
Example:
596
+
#### Single File Upload
597
+
598
+
When `singleFileUpload()` is enabled, the field value is a single integer (the file ID) or `null`.
599
+
The value is added to the `data` sub-array of the parameters array, making it suitable for direct database column mapping.
When `singleFileUpload()` is not called, the field defaults to accepting multiple files.
612
+
The field value is an array of file IDs.
613
+
Since arrays cannot be stored in a single database column, the field automatically registers a [custom form field data processor](validation_data.md#customformfielddataprocessor) that places the array of file IDs into the `$parameters` array directly, using the object property as the array key.
614
+
615
+
This means the file IDs will **not** be part of `$parameters['data']` and must be handled explicitly in your code.
616
+
617
+
```php
618
+
FileProcessorFormField::create('attachments')
619
+
->objectType('foo.bar.example')
620
+
->label('foo.bar.example.attachments')
621
+
```
622
+
623
+
The file IDs are available in the form data under the object property key:
624
+
625
+
```php
626
+
$formData = $this->form->getData();
627
+
628
+
// File IDs are in the top-level parameters array, not in 'data'.
629
+
$fileIDs = $formData['attachments']; // int[]
630
+
```
631
+
632
+
If the default data processor does not match your data structure, you can add your own `CustomFormDataProcessor` after building the form.
633
+
The following example converts the array of file IDs to a comma-separated string for storage in a single database column:
634
+
635
+
```php
636
+
$this->form->getDataHandler()->addProcessor(
637
+
new CustomFormDataProcessor(
638
+
'attachments',
639
+
static function (IFormDocument $document, array $parameters) {
0 commit comments