Can php populate a html form?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andys22
Forum Newbie
Posts: 7
Joined: Wed Mar 15, 2006 10:01 am

Can php populate a html form?

Post by andys22 »

Hi, I have written some php code to pass the contents of a text document to a variable.

I now need to populate a form text area with that variable but am not sure how to do it as I am new to php.

My code looks like this:

Code: Select all

<FORM action="savetodb.php" method="post">
	Update Wiki:<BR>
  <TEXTAREA name="wiki_text" cols="100" rows="30"></TEXTAREA><BR>
	<INPUT type="submit" value="Update Wiki">

<?php
      $filename="wiki.data";
      $fp = @fopen($filename, "r") or die("Couldn't open file");
      $data = fread($fp, filesize($filename));
  
      while(!feof($fp))
      {
      $data .= fgets($fp, 1024);
      }
      fclose($fp);

      $values = explode("\r\n", $data);
      TEXTAREA name="wiki_text" value=$data;
?>
</FORM>
It is a mess at the moment as you can see. All I am trying to do is get some text from a text file into my form. Any help would be gratefully recieved.

Thanks,

Andy.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Wrong forum, mate ;)

Get the information from the file first, then:

Code: Select all

<?php
//get information
?>
<textarea name="wiki_text" cols="100" rows="30"><?php 
print $textarea_information; 
?></textarea>
Get the idea?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Be aware that if anyone puts a newline into their textarea, then it will be treated as two (or more) seperate entries in your text file as the textfile information is split by newlines...
andys22
Forum Newbie
Posts: 7
Joined: Wed Mar 15, 2006 10:01 am

Post by andys22 »

I get the idea but will php rememeber the string variable after u close the tags i.e.

<?php //get variable $string ?>
<?php print $string ?>
andys22
Forum Newbie
Posts: 7
Joined: Wed Mar 15, 2006 10:01 am

Post by andys22 »

It seems that it does. Cheers Grim. I will buy you a pint if you do the rest of my assessment for me. haha
Post Reply