Page 1 of 1

how to display info from form on another page

Posted: Tue Apr 04, 2006 8:47 am
by maciek4
I want to gather information from the user and display it on another page.

In the file commit.php I have 2 fields

Product name:
Description:

Code: Select all

<form action="add_new.php" method="POST" name="submit">
<TR><TD ALIGN="right" VALIGN="middle" width="40%"> Product name:&nbsp;
</TD> 
 <TD ALIGN="right" valign="middle"><input name="name" size="27" type="text"></TD>
 </TR>
 <TR><TD ALIGN="right" VALIGN="middle">Description:&nbsp;</TD>
   <TD ALIGN="right">  <textarea name="desc" rows="5"></textarea>
   </TD>
   </TR>
</form>
And in the file add_new.php I want to display whatever text user wrote in those two fields Product name and description.

Code: Select all

<?php
	                
if (isset ($_POST['name']) || isset ($_POST['desc']))
   {
   echo'<form action="add_new.php" method="POST" name="submit">
   <TR><TD ALIGN="right" VALIGN="middle" width="40%"> Product name:&nbsp;
</TD> 
 <TD ALIGN="right" valign="middle"><input name="name" size="27" type="text" value="'.$_POST['name'].'"></TD>
 </TR>
 <TR><TD ALIGN="right" VALIGN="middle">Description:&nbsp;</TD>
   <TD ALIGN="right"><textarea name="desc" rows="5" value="'.$_POST['desc'].'"></textarea>
   </TD>
   </TR>
   </form>';
 }
 ?>
Unfortunatelly nothing is displayed althought there are no errors.

Posted: Tue Apr 04, 2006 9:04 am
by maciek4
I partially solved it. I got rid of a href and its almost ok except for the textarea

Code: Select all

<textarea name="desc" rows="5" value="'.$_POST['desc'].'"></textarea>
Why its not displaying value I dont know :-(

Posted: Tue Apr 04, 2006 9:13 am
by maciek4
Used that

<textarea name="desc" rows="5">'.$_POST['desc'].'</textarea>

and now it works.

Posted: Tue Apr 04, 2006 9:18 am
by JayBird
Yup, that is the correct way to do it with text areas. It's slightly different to other form elements