Submit form in modal bootstrap window, and refresh the window with submitted information [closed]

-2

Good morning! I have a modal window, where I load a list that comes from the database, I display it to the user, and there is a field where an edit occurs, where I created a form, and from there I give the update to my bank. The issue works perfectly, my only problem at the moment is, once the information is updated in the bank, I wanted the page to refresh the page and to open the modal in which the edit is made. Not put code because I did nothing related because of lack of content or knowledge in the subject. Thanks in advance for your attention.

    
asked by anonymous 20.06.2016 / 16:54

1 answer

1

Considering that your page refresh, in this case it suffices that the php file that processes the form returns a parameter to the page.

You can do this in two ways: Via $_GET or Via $_SESSION

  • VIA $ _GET:

Just pass the paramenter via URL:

Page that processes the form:

if ($atualiza == true){
    header('location:pagina.php?sucesso=1');
}

Mod page

<div id="myModal" class="modal fade <?=((isset($_GET['sucesso']))?'visivel':'')?>" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">...</div>
      <div class="modal-body">...</div>
      <div class="modal-footer">...</div>
    </div>
  </div>
</div>
  • VIA $ _SESSION:

Just create a message variable and arrow it:

if ($atualiza == true){
    session_start();
    $_SESSION['sucesso'] = 1;
}

Modal page:

<?php session_start();?>
<div id="myModal" class="modal fade <?=((isset($_SESSION['sucesso']))?'visivel':'')?>" role="dialog">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">...</div>
          <div class="modal-body">...</div>
          <div class="modal-footer">...</div>
        </div>
      </div>
    </div>
<!--Se a página não trabalha com sessões, você pode destruir a sessão após exibir a mensagem-->
<?php session_destroy();?>
<!--Se a página usa sessão pra outras coisas, ou se no fluxo da aplicação tem outros momentos que a sessão será utilizada após passar por essa página, nesse caso basta limpar o campo da mensagem-->
<?php unset($_SESSION['sucesso']);?>

Finally, your css should only display modal when class .visivel is set:

.visivel{
  display:block;
}
    
20.06.2016 / 17:53