upload image via a jquery ui modal form

990 views Asked by At

i am trying to upload an image through a jquery ui modal form..

is it possible? i am having problem on how to get the value from the modal..

i have been searching through the net but there is no clear answer..

do anyone have any idea about it?

this is my javascript code for the modal form:

 $("#dialog").dialog({
                modal: true,
                resizable: false,
                width: 400,
                position: "center",
                buttons: {
                    "Upload": function() {


                                                           var pos= $("#pos input:radio:checked").val();
                                                           // i still don't know how to get the value for the image uploaded

                                                           $( this ).dialog( "close" );

                                            },
                    "Cancel": function() { $( this ).dialog( "close" ); }
                                     }
            });
               });

this is my modal form:

<div id='dialog' title='ADD IMAGE' class='ui-dialog-content ui-widget-content'>
        <form id='myform' method='POST' enctype='multipart/form-data'>
        <fieldset>
        <div id='pos'>
        <p class='applyimage'>Where do you want to apply a background image?</p>
        <p class='applyimage'><input type='radio' class='position' name='position' id='header' value='header' checked='checked'/>&nbsp;<label for='header'>Header</label>
        <input type='radio' class='position' name='position' id='body' value='body'/>&nbsp;<label for='body'>Body</label>
        <input type='radio' class='position' name='position' id='footer' value='footer'/>&nbsp;<label for='footer'>Footer</label></p>
        <p class='applyimage'><input type='file' name='data[Image][fileName]' id='imgup'/></p>
        </div>
        </fieldset>
        </form>
        </div>
1

There are 1 answers

0
sonjz On

I'd suggest you don't use the "buttons" parameter, instead create the Upload button on your form.

If you do nothing else, it will load the action your form was set to.


If you really want to use the "buttons" parameter (to keep the style the same), you shouldn't have a problem forcing the submission of the form with javascript function() { $("#formName").submit(); }

I'd suggest doing an ajax call to do the submission though and catch it with the .success or .error handler to take the next step.

You'll have to work a lot with updating the modal div you created. And only close it after .success.