[jQuery.form] File upload sends multiple submit button name/value pairs

[jQuery.form] File upload sends multiple submit button name/value pairs

Hi all,

I'm using the jQuery.form plugin to upload files and have two submit buttons on the form. Uploading files using the first submit button works fine, but when using the second submit (after the first submit), the first submit name/value pair is also sent to the server causing my server to handle two actions, one for each button.

From the source code I think the issue is that when uploading files the submit button name/value is added to the 'opts.extraData' property which is later used to build hidden fields inside the form. The submit button name/value pair is not removed from the 'opts.extraData' after the submission. On subsequent submissions using the second submit button, the first button name/value is still present in 'opts'extraData' and send to the server as well.

Below is my not-so-elegant patch which seems to work for me. :) Tested in IE6 and FF3.6.

  1. --- Base (BASE)
  2. +++ Locally Modified (Based On LOCAL)
  3. @@ -259,6 +259,16 @@
  4.               extraInputs.push(
  5.                 $('<input type="hidden" name="'+n+'" value="'+opts.extraData[n]+'" />')
  6.                   .appendTo(form)[0]);
  7. +          if (sub) {
  8. +            var sn=sub.name;
  9. +            if(sn && opts.extraData[sn]) {
  10. +              delete opts.extraData[sn];
  11. +              if (sub.type == "image") {
  12. +                delete opts.extraData[sn+'.x'];
  13. +                delete opts.extraData[sn+'.y'];
  14. +              }
  15. +            }
  16. +          }
  17.  
  18.           // add iframe to doc and submit the form
  19.           $io.appendTo('body');

Should I open a ticket for this as well?

Kind regards

Bob