Log in

View Full Version : PHP form to txt



BMANrules
03-12-2011, 09:59 PM
I have been using frontpage to build a social network .
i need a status code. So far i load a txt file from the server and display it as current status. I need a way for users to edit this txt file(there will be one for each user) from a php form. i tried it in frontpage but i need frontpage ser
er extensions which are discontinued.


to make it clearer i need a form with a submit button that edits a .txt file on the server. the website isnt live yet so i dont have a set domain name:confused:

BMANrules
03-12-2011, 10:03 PM
i tried this, no luck need server exstensions


<form>

</form>
<form method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" U-File="_private/form_results.txt"
S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><input type="text" name="T1" size="20"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

bluewalrus
03-12-2011, 11:09 PM
That is all your code? I dont use frontpage/ know how it works but I think it'll be easier to just do it all with PHP. Are you using a version of php =>5?

BMANrules
03-12-2011, 11:22 PM
do you know the php code
i need a form aswell as this not just save to file a form included in the code which users can type in thanks for quick reply

bluewalrus
03-12-2011, 11:39 PM
I know what you'd want to use it depends how much control you want the user to have though....

http://php.net/manual/en/function.file-get-contents.php
http://www.php.net/manual/en/function.file-put-contents.php
http://us3.php.net/manual/en/function.strip-tags.php

So you use the get contents and then echo the contents into a textarea. Your probably going to want this to be controlled by a wysiwyg editor.

http://en.wikipedia.org/wiki/CKEditor
http://en.wikipedia.org/wiki/TinyMCE
http://tinymce.moxiecode.com/
http://ckeditor.com/

You'll then want to save the contents once the user submits the new form with the put contents. You dont want to allow all tags in their input if it's being displayed to other users. If you don't have HTML content in the text file you wont need the wysiwyg but then there wont be much formatting with it. If you post the context of the text being inputted I can be more specific.

BMANrules
03-13-2011, 01:16 PM
Context:
There will be a one line text box , a submit button and a reset button.
The user enters text into the text box (like right now i'm ...) and presses submit.
the text in the text box is saved to a form_results(1,2,3. one for each user).txt file. then when someone visits their page it loads the .txt file like this
<p>Current Status:</p>
<iframe name=my_frame src=LOCATION OF FILE/form_results.txt height=10% width=20% frameborder=0 scrolling=auto marginheight=5 marginwidth=5></iframe>

bluewalrus
03-16-2011, 04:56 AM
Not sure what you have there but a simple example would be


<?php
$file = "file.txt";
if (!empty($_POST['submitted'])) {
$txt = file_put_contents($file, strip_tags($_POST['file_contents']));
echo "File saved.";
exit();
}
$txt = file_get_contents($file);
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<textarea name="file_contents"><?php echo $txt;?></textarea>
<input type="submit" name="submitted" />
</form>