1

I am using Dropzone and the bootstrap example to upload files. I want to also POST additional data. I have tried a number of variations after reading the answers to other questions but I can't quite get the syntax right to get the data from the input statement as I am not very experienced with javascript.

I have two fields

<input type="text" name="firstname" id="firstname">
<input type="text" name="lastname" id="lastname">

and I have tried to add params

params: {
  firstname: ?????,
  lastname: ?????,
},

I know that the method works as if I use

params: {
  firstname: "abcde",
  lastname: "vwxyz",
},

then abcde and vwxyz are posted. I just can't get the data from the input statements to POST.

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135

1 Answers1

0

The question is divided to 2.

  1. How to get the values of the inputs.
  2. How to pass params to Dropzone.

The answers:

  1. Using document.querySelector and .value (See this this answer).
  2. Since the inputs are empty when you initlize Dropzone, params should be a function that retrieve the values when you need them (e.g. click start).
params: () => ({
  firstname: document.querySelector('#firstname').value,
  lastname: document.querySelector('#lastname').value,
}),

https://jsbin.com/neteker/edit?js,output

More info about params

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
  • Unfortunately this does not work. It only works if I enter a value attribute to the input field such as . It then posts the value rather than the user input. I had looked at the answer you suggested but encountered the same problem. – user3538252 Jul 11 '21 at 23:55
  • Odd. Can you add a working example to your question using the snippet tool or external tools such as jsbin.com, codepen etc.? – Mosh Feu Jul 12 '21 at 06:32
  • I have uploaded my files to both jsbin.com/kecudil/ and codepen.io/lmb21/pen/mdmOZvG. The upload.php should receive the files and posted firstname and lastname, and the session variables appid and schid and send them all to a mysql database with one record per file. All works well except for the firstname and lastname. Thanks for your help with this. – user3538252 Jul 13 '21 at 10:30
  • A bit late but I've updated my answer and included example. – Mosh Feu Jul 22 '21 at 14:12
  • Thank you so much for your help. It is now working. – user3538252 Aug 07 '21 at 05:45