Log in

View Full Version : an Idea possible



bluewalrus
10-15-2008, 06:31 PM
This is an idea i had to make 3 page instead of 20. There are going to be 12 of these forms on this page. I'm going to use a toggle to show the files the user can edit. The submit will only submit the form it is in correct? And will the input type="hidden" name="page" value="alumni" pass over and open the text file associated with it in the submitpage.php.
This is the code for the first page where there will be a list of files:


<form method="post" action="submitpage.php" style="border:#000000 2px solid; width:750px;">
<input type="hidden" name="page" value="alumni" />
<textarea name="data" rows="20" cols="90">
<?php
$myFile = "alumni.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 20000000);
fclose($fh);
echo $theData;
?>
</textarea>
<input type="submit" value="Submit Changes" style="text-align:center; font-family:Geneva, Arial, Helvetica, sans-serif; font-size:14px;" />
</form>

This is the submitpage.php


<?php
$notes = $_POST['data'];
$page = $_POST['page'];
$File = ($page . ".txt");
$Handle = fopen($File, 'w');
$Data = $notes;
fwrite($Handle, $Data);
fclose($Handle);
echo "The" . $page . "page has been updated.";
?>

Thanks for any suggestions or answers you can offer.

Jesdisciple
10-15-2008, 10:12 PM
You might be interested in file_get_contents (http://us3.php.net/manual/en/function.file-get-contents.php) and file_put_contents (http://us3.php.net/manual/en/function.file-put-contents.php).

Yes, a submit button will only submit its own form, and the hidden field will work as you intend. But why are you using 12 forms? Why not use a select box full of the 12 possible file names?