phpfile-uploadmultifile-uploaderfilepond

Filepond: how to configure filepond to have more than 1 filepond field in the same form?


I want to have 2 different file upload field in a form and use filepond to manage image upload nicely. I could use filepond without problems with one single field in a form so far, using the code provided by the documentation.

I assumed I could put more than one field with the following changes:

Code:

<input name="filepond_one[]" id="file_one" type="file" accept="image/jpeg" class="filepond" multiple />
<input name="filepond_two[]" id="file_two" type="file" accept="image/jpeg" class="filepond" multiple />
<script src="js/filepond.min.js"></script>
<script src="js/filepond-plugin-file-validate-size.min.js"></script>
<script src="js/filepond-plugin-image-edit.min.js"></script>
<script src="js/filepond-plugin-image-exif-orientation.min.js"></script>
<script src="js/filepond-plugin-image-preview.min.js"></script>
<script>
    FilePond.setOptions({
      maxFiles: 4,
      maxFileSize: '2MB',
      imageResizeTargetWidth: 1200,
      labelIdle:                      'Drag and Drop up to 4 photos',
      labelFileProcessing:            'Uploading',
      labelFileProcessingComplete:    'Upload complete',
      labelFileProcessingAborted:     'Upload cancelled',
      labelFileProcessingError:       'Error during upload',
      labelFileProcessingRevertError: 'Error during revert',
      labelFileRemoveError:           'Error during remove',
      labelTapToCancel:               'tap to cancel',
      labelTapToRetry:                'tap to retry',
      labelTapToUndo:                 'tap to undo',
      server: 'photos/filepond/'
    });
    FilePond.registerPlugin(
      FilePondPluginImagePreview,
      FilePondPluginImageExifOrientation,
      FilePondPluginFileValidateSize,
      FilePondPluginImageEdit
    );
    const inputElements = document.querySelectorAll('input[type="file"]');
    Array.from(inputElements).forEach(inputElement => {
      FilePond.create(inputElement);
    })
</script>

The change applies the filepond style correctly to both inputs, however changing the name of the input seems to break the upload.


Solution

  • Digging into the filepond folder, I saw this in the config.php file:

    // where to get files from
    const ENTRY_FIELD = array('filepond');
    

    So I added the field names I wanted to use as such et "voila" !

    // where to get files from
    const ENTRY_FIELD = array('filepond', 'filepond_one', 'filepond_two');
    

    Hope this helps others as I got stuck on this for a day :-)