Jump to content

Displaying Form results on same page


MasterACE14

Recommended Posts

How can I make a form like the following?:

<form method="post" action="commentpage.php">
<textarea rows="5" cols="20" wrap="physical" name="comments">
Enter Comments Here
</textarea>
<input type="submit" value="submit">
</form>

<?php
echo "$_POST['comments'] was your comment";
?>

 

I just want to have a form that does everything on one page, instead of being sent to another page with "action="anotherpage.php""

 

Regards ACE

 

Link to comment
https://forums.phpfreaks.com/topic/69548-displaying-form-results-on-same-page/
Share on other sites

I'm having no luck here, Basically, the form is used to search for elements or values in a 2 dimensional array. And then echo it if it has found it.

 

heres the code:

<?php // encyclopedia 

/* includes */
include '/home/ace/public_html/conflictingforces/weapons.php';
?>

<div id = "encyclopedia">
<center><b><u>Encyclopedia - Beta</u></b><br></center><br>

<fieldset><legend>Search</legend>
<?php
if(isset($_POST)) 
{
   // Handle
   // Display
   echo 'Item is '.array_search($_POST["item"],$weapons);
   

}
else
{ // Show form
?>
<form method="post" action="index.php?page=encyclopedia">
item: <input type="text" size="15" maxlength="60" name="item">
  <input type="submit" value="Search">
  </form>

<?php	 
}
?>




</fieldset>

<br>

<center>
<center>

            


            
	<?php /* Grab weapon Array and Display it */

for ($row = 0; $row < 3; $row++)
{
echo "<table class=\"fix\">";
echo "<tr><td colspan='2'>WEAPON</td></tr>";


    foreach($weapons[$row] as $key => $value)
    {

	echo "<tr>";
        echo "<td>".$key."</td>";
	echo "<td>".$value."</td>";
	echo "</tr>";

    }

}

echo "</table>";

?>


	</center>
	</center>

</div>

 

Regards ACE

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.