Post + form + action + results on the same page

Question

I’m trying to put on a post a custom form and, on the same page I’d like to visualize the results of an action on the form.

But I’m missing the basics.

Essentially I’d like to do something like this. Is it possible?

<?php
    if(isset($_REQUEST['submit_btn']))
    {
       echo "<div>";
       $name = $_POST["names"];
       echo "</div>";
    }
?>

<form action="" method="POST">
   <input type="text" name="names" id="names">
   <input type="submit" value="submit" name="submit_btn">
</form>

ADDITION (after the answer from Tejas gajjar):

Thank for the answer. Actually I don’t need to interact with the DB so I removed some of the suggested lines.

If I use this:

enter image description here

Question: Do you know why it renders like this?:

enter image description here

ADDITION (after the comment from Milo):

OK it worked. I was even able to access the form field.

<form action="" method="POST">
   <input type="text" name="names" id="names">
   <input type="submit" value="submit" name="submit_btn">
</form>

[insert_php]
    if(isset($_REQUEST['submit_btn']))
    {
       echo "<div>";
       $name = $_POST["names"];
       echo "</br>";
       echo "ANSWER:</br></br>", $name;
       echo "</div>";
    }
[/insert_php]
0
, , Mario Stefanutti 2 years 2020-01-04T08:38:52-05:00 0 Answers 96 views 0

Leave an answer

Browse
Browse