jQuery modal dialog form

jQuery modal dialog form

hello all (first time poster here...).

I have a problem with a form in a modal dialog that I'm hoping somebody can help me with. I see several different permutations of such scenarios in other posts here, but I haven't been able to find one which matches what I'm trying to do...

Here's the setup (containing a bunch of my assumptions which I believe to be correct, but please point out if I have anything wrong here!):

1. I have a form contained in a modal dialog
2. I need to use the form's post method itself, rather than using, say, an ajax method to post the data, because in at least one of the forms I have to create, I need to upload a file. I'm pretty sure that the only way to do this is to use the native html post from the form.
3. I have a button which I want to use to trigger the form's post method
4. It would be nice if the default form method (ie hitting return when on one of the text boxes) worked also.
5. I need the dialog box to close afterwards.


Abbreviated version of the code, hopefully without introducing typos:

$('<div id="dialogdiv"><form id="form" method="post" action="..." target="hiddenframe">....</form></div>').appendTo(somewhereonthepage);

$('#dialogdiv').dialog( {
      autoOpen : false,
      modal      : true,
      buttons      : {
            Go      : function() {
                  $('#form').submit();
            },
            Cancel      : function() {
                  $(this).dialog('close');
            }
      },
      close : function() {
            allFields.val( "" ).removeClass( "ui-state-error" );
      }
});

I actually have tried several different combinations of things, each of which fail to do what I want in somewhat different ways...

This version will submit the form either on default action (hitting return) or pressing the "Go" button, but both leave the dialog box open.

On the other hand, if I bind another function to the "submit" event (either on the form or the enclosing div) the box will close on pressing the "Go" button, but will not actually submit the form.  It still submits it on form default action, though.

Any ideas much appreciated...

The above is abbreviated for clarity, as I mentioned. I'll boil what I have down into a small actual executable example and post when I can also.