How can I open a modal after a submit event

0

I need to open a modal after a submit occurs on a particular button, I wanted to know if there is an event for it, something like post submit.

    
asked by anonymous 07.12.2016 / 17:53

2 answers

2

Apparently you're using jQuery, so just use event.preventDefault ()

something like

$('#meuform').on('submit', function(event){
    event.preventDefault();
    //abre a modal aqui
});

This will prevent the action default of the event, in this case, send ( submit ) of the form, and will allow to open its modal.

As a side effect the sending of the data will have to be done via ajax.

There is a "gambiarra" that depending on what you need can work. It consists of giving return false instead of using preventDefault() , usually used to do some kind of validation via js before sending.

$('#meuform').on('submit', function(event){
    if(!validaForm()){
        //abre a modal aqui
        return false;
    }
});
    
07.12.2016 / 17:59
1

One option is to prevent the page from being reloaded using event.preventDefault :

$( "#form" ).submit(function( event ) {
  event.preventDefault();
  $( "#dialog" ).show();
});
    
07.12.2016 / 17:57