Skip to content Skip to sidebar Skip to footer

Append All Data From Form (including Files) To Formdata

I'm unable to get the correct syntax for adding a file (or multiple files) when scanning all elements from a
. The problematic line is data.append('PhotosToUpload', The

Solution 1:

You're overcomplicating things. You don't need to think about the individual elements at all. Just give the FormData object your form and let it take care of finding the data in it.

var form = document.getElementById("MyForm");
var data = newFormData(form);
xhr.send(data);

Note that PHP requires special naming conventions when you have multiple values for the same field name.

name="PhotoToUpload" needs to be name="PhotoToUpload[]"

Post a Comment for "Append All Data From Form (including Files) To Formdata"