3

I am trying to convert an existing HTML form and make it appear in JQuery dialog. I am not sure how to change the code so the data is submitted after clicking the submit buton. My code is a follows:

Old form:

<form method="post" name="callbackrequest" id="ccallbackrequest" action="action.php" onsubmit="return validateThis(this)">

<button type="submit" class="submit">Submit Request</button>

New form:

buttons: {
                "Submit": function() {
if ( bValid ) {

        HERE GOES THE CODE!

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

Then there is the new form:

<form class="center" method="post" name="callbackrequest" id="ccallbackrequest" action="??">
 fields listed
no submit button
</form>

Any advice on how should I handle this?

2
  • Could you make a jsfiddle and show us what is breaking? I'm not sure what is breaking, or what behavior you want... jsfiddle.net Commented Apr 7, 2011 at 14:22
  • Nothing is braking, it is not working. I am just trying to submit the button and I don't know the code to do this in JQuery. In the HERE GOES THE CODE section there should be a call to submit the form, however i dont know how to do it. Commented Apr 7, 2011 at 14:30

3 Answers 3

12

Let's take it one step further...here's a dialog form submit with ajax!

<form id="modalform" style="display:none">
     <input type="text" name="something">
     <input type="text" name="somethingelse">
</form>




$("#modalform").dialog({                                                            //Shows dialog
        height: 250,
        width: 450,
        modal: true,
        buttons: {
            "Cancel": function() {
                $( this ).dialog( "close" );
            },
            "Save": function() {
                $.ajax({
                    url: "/url/to/submit",                   //
                    timeout: 30000,
                    type: "POST",
                    data: $('#modalform').serialize(),
                    dataType: 'json',
                    error: function(XMLHttpRequest, textStatus, errorThrown)  {
                        alert("An error has occurred making the request: " + errorThrown)
                    },
                    success: function(data){                                                        
                         //Do stuff here on success such as modal info      
                             $( this ).dialog( "close" );
            }
        }
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Although, I'm quite familiar with ajax, I was not sure how I was going to implement this with dialog. This was extremely helpful, thank you!
6

Try $('#ccallbackrequest').submit();. The submit method just submits whichever form is returned by the selector.

Comments

3

You just need to put in

 $("#FORM_ID").submit()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.