Monday, August 27, 2012

Adding form varibles to Uploadify / Uploadifive

I started using this very nice script (Uploadify) to allow users to upload files to our server. One problem I found was that you can not add other inputs to the upload except at form load time. I found this to be annoying. And while there are some workarounds, I thought it wasn't as good as simply adding all the form sibling inputs to the upload. So, I modified the source code to allow uploading the sibling inputs.

If you find the lines here:
// Add the rest of the formData

for (i in settings.formData) {

      formData.append(i, settings.formData[i]);

}

And add in this code:
var parentform = $('#' + settings.id).closest('form');

$(parentform).find('input[type="text"], input[type="hidden"], select, textarea').each(function() {

    formData.append(this.name, this.value);

}

);


It will automatically add other (non-file) form inputs to the upload data.

4 comments:

  1. unable for multiple upload, like my ss -> http://prntscr.com/2fyxni

    ReplyDelete
  2. fixed form multiple upload

    file.queueItem.find('input[type="text"], input[type="hidden"], select, textarea').each(function() {
    formData.append(this.name, this.value);
    }
    );

    ReplyDelete