Open modal window with php function going through JS

0

I need to click on a button, open a modal with a form for inserting data into mysql. I'm adapting a code I used earlier to display iframe, but when the modal opens it shows the page inside the iframe with the function in php. I need only within the modal open the form to fill. Following:

Admin.php

 <li> <a role="button" data-toggle="modal" href="#insere" class="fa fa-info-circle"  style="font-size:18px"> Inserir</a></li>
  <div class="modal fade" id="insere" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">

        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close blank" title="Fechar" data-dismiss="modal" aria-label="Fechar"><span aria-hidden="true">&times;</span></button>
                    <h2 class="modal-title text-center">Inserir</h2>
                </div>
                <div class="modal-body text-center">
                    <iframe width="100%" height="900px" frameborder="none"></iframe>
                </div>
            </div>
        </div>
    </div> 
    <script type="text/javascript">
    //função JS
  $('#insere').on('show.bs.modal', function () {
  $('#insere iframe').attr('src','?insere');
  });
     $('#insere').on('hide.bs.modal', function () {
$('#insere iframe').removeAttr('src');
 });
 </script>

Commands.php

if (isset($_GET['insere'])) {
<form id="executainserir" method="post" enctype="multipart/form-data">
<strong>Inserir documentos no banco de dados:</strong>
<table width="1075" border="1">
<tbody>
<tr>
  <td width="180" scope="col">Título:
    <input name="titulo" type="text" autofocus required title="Título" size="30"></td>
  <td width="498" scope="col">Descrição:
    <input name="descricao" type="text" required title="Descrição" size="83"></td>
  <td width="375" scope="col">Link:
    <input name="link" type="url" value="http://" size="62"></td>

</tr>
</tbody>
</table>
<input name="arquivo" type="file" accept=".pdf" required title="Arquivo com extensão *.pdf" id="arquivo"><br> 
<input type="submit" name="executainserir" value="Gravar">
</form>
    
asked by anonymous 07.07.2016 / 15:40

2 answers

1

I believe you will need an AJAX .

When you click the modal button, make a GET via AJAX, returning the contents of the Commands.php page (which in this case would be the html form), with that return, just the element that will display this form is popular. would be .modal-body ).

    
07.07.2016 / 15:55
0

Well, first of all:

$('#insere iframe').attr('src','?insere'); 

should be

$('#insere iframe').attr('src','comandos.php?insere');

However, as Denis Bernardo said, the ideal is an AJAX request for commands.php and ideally with 'POST' method and abandon the GET.

I assume the purpose of this code is to upload with animation or indication of progress, but this technique (via iframe) is discouraged to the maximum. There are lighter, easier, and safer alternatives. See: link

    
09.11.2017 / 08:59