Submit a form in a popup, and then close the popup

后端 未结 5 1724
终归单人心
终归单人心 2020-12-13 05:23

This seemed so trivial when I started off with it! My objective is this:

  • When user clicks on a button, open up a form in a new window.
  • Once the form
5条回答
  •  天命终不由人
    2020-12-13 05:43

    I know this is an old question, but I stumbled across it when I was having a similar issue, and just wanted to share how I ended achieving the results you requested so future people can pick what works best for their situation.

    First, I utilize the onsubmit event in the form, and pass this to the function to make it easier to deal with this particular form.

    Certificate 1:
    Certificate 2:
    Certificate 3:

    In our function, we'll submit the form data, and then we'll close the window. This will allow it to submit the data, and once it's done, then it'll close the window and return you to your original window.

    
    

    Hope this helps someone out. Enjoy!


    Option 2: This option will let you submit via AJAX, and if it's successful, it'll close the window. This prevents windows from closing prior to the data being submitted. Credits to http://jquery.malsup.com/form/ for their work on the jQuery Form Plugin

    First, remove your onsubmit/onclick events from the form/submit button. Place an ID on the form so AJAX can find it.

    Certificate 1:
    Certificate 2:
    Certificate 3:

    Second, you'll want to throw this script at the bottom, don't forget to reference the plugin. If the form submission is successful, it'll close the window.

     
     
    
        
    

提交回复
热议问题