I am fairly new to PHP, and I know how to get the information if in another PHP file if I use it as the action. But I want to get the information on the same page as the form. Is that possible?
For example:

<form action="" method="post">
    <input type="text" name="t"/>
</form>
<?php
  //how to get the information in here?
?>

Thanks

Recommended Answers

All 2 Replies

Yes, it is possible to get information on the same page as the form. To do so, you can embed your php coding that do the action together with your form. With your php coding together on the same page, you can name the file itself at the form action or leave it empty will do the same. Note that, your file must be a php file if you have php coding inside the coding. Here is the sample:

// Assume filename is form.php
 
<form action="form.php" method="post">
    <input type="text" name="t"/>
    <input type="submit" name="Submit" value="Submit">
</form>
 
<?
if ($submit)
{
     if ( empty($t) )      
    {   
           echo "No information provided";
    }
}
?>

Note that, you can embed php coding anyway together with html coding depending on how you want to carry out the action. The arrangement of the coding might affect the outcome. But it is said to be good practice to separate the file between the form and the php action.

Hope it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.