Home > Software design >  WEB: Submitting files text fields, use single form or separate?
WEB: Submitting files text fields, use single form or separate?

Time:03-10

I'm currently working on a simple frontend that will allow users to input data into text fields and also upload files on the same form.

I know that I'll have to use multipart/form-data in order to send the files, but I'm curious as to what would be the best way to also send the text data. My options are:

  1. Submit files and text data in a single form using multipart/form-data

  2. Separate files and text data between two different endpoints, allowing me to format the text data to JSON client-side before sending it off

I don't think doing either would be terribly difficult, but I'm curious as to what is generally considered to be the best practice in this scenario.

CodePudding user response:

This depends on the workflow you expect of your users.

If the fields you want them to fill in are tightly bound to the file you upload, do them all in one form. For example, if it's an image being uploaded and the field contains the image's caption, they go together and should be in a single form.

If it makes sense from your page to just upload the file, or just fill out the fields in the form and submit them, use two form objects.

You probably won't know how well this works until you do some usability testing. You may have to change it up to get everything working smoothly.

  • Related