1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Open modal on form submit?

Discussion in 'XenForo Development Discussions' started by Mike Creuzer, Aug 14, 2015.

Tags:
  1. Mike Creuzer

    Mike Creuzer Well-Known Member

    Is it possible to open a modal when submitting a form?

    Thanks,
    Mike
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    There isn't really anything that can do it by default, so it would require custom code to handle it.

    Vaguely speaking if the form is being submitted using the AutoValidator then you can listen to certain events, prevent the default actions where applicable, and then just instantiate an overlay.

    There's a few code examples in XFMG where an overlay is launched entirely using JS, though none specifically as a consequence of submitting a form. In XFMG 1.1:

    Code:
    options = {};
    options.speed = XenForo.speed.fast;
    
    this.trigger = { href : $(this).attr('href') };
    
    this.OverlayLoader = new XenForo.OverlayLoader($(this.trigger), true, options);
    this.OverlayLoader.load();
    Where "$(this).attr('href')" is the URL of the overlay that needs to be opened.
     
  3. Mike Creuzer

    Mike Creuzer Well-Known Member

    Thanks for taking the time, Chris. Very helpful.

    Would you be able to actually send form data to this new modal? Or do you think Id need to store that data differently (in which case I don't really necessarily need the <form> tag).
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    You possibly could send form data into the overlay, yeah. Most "Preview" forms in XF work like that (e.g. Preview Post, Preview Notice).
     

Share This Page