PHP page inside a DIV after Submit

Asked

Viewed 516 times

1

I have a form where the user type what equipment he wants to consult and
AFTERWARD to click confirm, I need the fields with the information appear. These fields are in another PHP file that will make the selects based on the data selected in the form. Using Hidden doesn’t meet my needs

<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> 

Data must appear inside the DIV above.

  • 1

    You can use Ajax and make the request for this php file. After return you populate your div with the information you need.

  • Can you tell me how to do this?

  • I think I understand your idea, but the logic for your need may be better... instead of you inputar via include a file after the action in the form, you can just make an innerHtml() or an append, and use these methods (javascript) to insert code fragments and sequence their logic. For this, Voce uses the serialize to send the form via ajax and in return vc checks if it was ok your Submit and loads the return.

1 answer

2


Without using Ajax, you can make a POST to the same page and condition the display of div receipt of the value of the form.

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

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
}
?>
  • Thanks friend, tomorrow I will be able to perform the test and confirm if it worked. Until then it seems that is exactly what I need.

  • Blz... at least here I test everything before posting, and quiet funnel. Abs!

  • I tested and worked perfectly, thank you very much.

Browser other questions tagged

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