if you want to combine this 2 files in 1, you would need to add an if statement checking for the submition of the form.
first change the form's action to your current file (and maybe closing the php tag before the html, that way you can take advantage of html highlighting instead of a string):
php Code:
/** edit-text.php **/<?php $myFile =
"../includes/docs/sdata.txt";
$fh =
fopen($myFile,
'r');
$theData =
fread($fh,
filesize($myFile));
fclose($fh);
?> <form action=
"<?php echo __FILE__; ?>" method=
"post" enctype=
"multipart/form-data">
<label
for=
"templateedit">Edit template script</label><br /
<textarea name=
"templateedit" cols=
"90" rows=
"20" id=
"templateedit">
' . $theData . '</textarea><br><br>
<input type=
"submit" name=
"save" value=
"Save Template script" />
<!--changed the button
for an actual submit button-->
</form>
Then what you would need is have a big if statement making sure if the submit button value is empty or not, if it is not. If it is not empty (or not set) then the form hasn't been submitted. something like this:
php Code:
<?phpif(isset($_POST[
'save']
) && !
empty($_POST[
'save']
)) { //put here what would you need to do to process the submitted info //in this case, what you have in your second file in your example, without the header() call}$myFile =
"../includes/docs/sdata.txt";
$fh =
fopen($myFile,
'r');
$theData =
fread($fh,
filesize($myFile));
fclose($fh);
?> <form action=
"<?php echo __FILE__; ?>" method=
"post" enctype=
"multipart/form-data">
<label
for=
"templateedit">Edit template script</label><br /
<textarea name=
"templateedit" cols=
"90" rows=
"20" id=
"templateedit">
' . $theData . '</textarea><br><br>
<input type=
"submit" name=
"save" value=
"Save Template script" />
<!--changed the button
for an actual submit button-->
</form>
To close I would suggest using $_POST instead of $_REQUEST to access the form info. Request mangles all types of request together, which IMO brings an obscurity when handling requests.
Also take a look to the functions
file_get_contents and
file_put_contents, they might save you some file handling coding.