Page 1 of 1

Can php populate a html form?

Posted: Wed Mar 15, 2006 10:15 am
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.

Posted: Wed Mar 15, 2006 10:20 am
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?

Posted: Wed Mar 15, 2006 10:22 am
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...

Posted: Wed Mar 15, 2006 10:29 am
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 ?>

Posted: Wed Mar 15, 2006 10:32 am
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