anandmainali5's avatar

How to use Dropzone.js with additional field and submit button

I want to use Dropzone.js for multiple image upload. I also wanna add a image title field and the image should be uploaded when i hit the submit button? Can u plz help me??

0 likes
6 replies
burlresearch's avatar

when you drop multiple files into the dropzone file upload box, each one will be posted to the endpoint you specify, then you should be able to handle each request with something like:

$this->validate($request, [ 'file' => 'required']);

/** @var UploadedFile $file */
$file = $request->file('file');

if($request->file('file')->isValid()) {
    $ret['fname'] = $fname = $file->getClientOriginalName();
    //...
}
anandmainali5's avatar

@burlresearch But when i drop the files it is automatically uploading. I also want extra text field in the form and when i hit the submit button then the data is submitted.

burlresearch's avatar

for that you probably don't want Dropzone, just use an <input type="file"... in your form.

Or, if you want to use Dropzone for multi-file input, then use a 2-phase approach. Where,

  1. when the files are dropped into the dropzone widget, upload them all, and return the stored filename from each.
  2. accumulate the stored filename in a <input type="hidden" and then just submit with your form, along with the other submitted data.

This 2-phase approach is nice from a UX perspective also, since while the files are uploading then your users are busy filling out the rest of the form, so when the finally submit, the data is already there.

1 like

Please or to participate in this conversation.