Submit form in modal bootstrap window, and update window with submitted information

Asked

Viewed 641 times

-2

Good morning! Guys, my difficulty is the following: I have a modal window, where I load a list from the bank, display it to the user, and there is a field where there is an edition, where I created a form, and from there I update it in my database. The edition works perfectly, my only problem at the moment is, once the information is updated in the bank, I wanted the page of this refresh on the page and already open the modal in which the edition is made. Not put code because I did nothing related for lack of content or knowledge in the subject. Thank you for your attention.

  • Well, it gets a little difficult, but come on. Is this form static on the page or is it dynamic ? Example, I have a list and each row of the list the information in the modal changes.

  • When refresh is done, you could create a flag and play on a Hidden input, then capture that value with javascrip. When the DOM is ready, you check if that flag is TRUE. If so, open the modal. If not, do nothing.

  • If you are using javascript or Jquery, add the TAG, because the solution I will give is through the client server.

1 answer

1

Considering that your page refreshes, in this case it is enough that the php file that processes the form returns a parameter to the page.

You can do it two ways: Via $_GET or Via $_SESSION

  • VIA $_GET :

Just pass the parameter via URL:

Page processing the form:

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

Modal 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 it is enough that your css displays the modal when the class .visivel was set:

.visivel{
  display:block;
}
  • From what I understand, you want after the update in the bank the page give refresh opening the modal and showing the user the page in exactly the same state that it was before sending the form. In this case it would not be more intuitive to perform this operation without refresh?

  • And how I do this operation without using refresh Adriano?

  • @Joséallison you can use ajax. It could be the javascript xmlhttp request procedure or the jquery $.ajax (Extremely simple, I recommend). Here I have an example of ajax with query, take a look: http://answall.com/questions/125686/como-usar-ajax-para-fazer-select-where/125745#125745

Browser other questions tagged

You are not signed in. Login or sign up in order to post.