PHP page within a DIV after submitting

1

I have a form where the user types which equipment he wants to consult and AFTER to click confirm, need the fields with the information to appear. These fields are in another PHP file that will make the selects based on the data selected in the form. Using hidden does not meet what I'm needing

<form method="post" action="test.php">      
        <label style="margin-top: 5px;">
            <span style="margin-right: 18px;">Equipamento:</span>
            <input type="text" name="equipamento" id="equipamento" size="12" style="margin-top: 5px;" autofocus required>
        </label>
        <input style="margin-left: 20px;" type="submit" name="submit" value="Confirmar">
</form>
    <br>
        <div> <?php require_once("test.php"); ?> </div> 

The data needs to appear within the above DIV.

    
asked by anonymous 24.05.2018 / 19:28

1 answer

2

Without using Ajax, you can do a POST to the same page and condition the div display to receive the form value.

Include you send the value received via GET to the test.php page. So, after submitting the form, the page test.php included in div will return with HTML based on the parameter sent via GET.

It would look like this:

<form method="post">      
  <label style="margin-top: 5px;">
      <span style="margin-right: 18px;">Equipamento:</span>
      <input type="text" name="equipamento" id="equipamento" size="12" style="margin-top: 5px;" autofocus required>
  </label>
  <input style="margin-left: 20px;" type="submit" name="submit" value="Confirmar">
</form>
<br>
<?php
// só irá mostrar a div se houver valor
// enviado pelo formulário
$equipamento = $_POST['equipamento'];
if(!empty($equipamento)){
?>
<div>
   <?php
   $_GET['equipamento'] = $equipamento;
   require_once("test.php");
   ?>
</div> 
<?php
}
?>

Page test.php :

<?php
$equipamento = $_GET['equipamento'];
if(!empty($equipamento)){
   // faz alguma coisa com a variável $equipamento
   // que é a string enviada pelo formulário
}
?>
    
24.05.2018 / 20:04