Click to See Complete Forum and Search --> : type and post in textarea


Code One
11-15-2003, 12:08 AM
Hey,
I'm trying to find a way to be able to capture a string of text, from an input box, and have the users string, post in the textarea. I'm going to use it as a simple guestbook. I just would like for them to type whatever they like, and hit post, it doesn't matter if they submit, 0 or 1000 times to me. Just a type and post in textarea, will do.

Thanks,

Code One

Adrian Girling
11-15-2003, 11:38 AM
Sorry if I am letting the JavaScript side down her, but this kind of thing is fairly easy to do with php. It may be possible with Javascript too, but I am even more of a beginner at that!

But since your post has been up for some hours it occurs to me that maybe it isn't easy in Javascript?

If I have understood your requirement, the php page could be a simple html form with text input field, followed by a the previous messages which could be stored in a simple text file with just a long string of html script which, when opened and read, is 'echoed' to the screen.

When the user submits his message, the php page calls itself, carrying the new message as a variable. (if the user arrives new to the page, the variable will be null). The new message is then appended to the stored text file so that is shows when all the messages are 'echoed'

If you would like further clarification, please let me know.

Adrian

Code One
11-15-2003, 04:31 PM
that was the big problem I had with it, I got it to work and dumb me didnt even ralise that once a user types a message and leaves the site, the post will be gone the next time they come back. I would definently like to know how you would setup a data file so the users strings would be saved and remain visible, in the chat box. here's what I got to work with:


<html>
<head>
<script>
function fred(){
document.sam.jaws.value+=document.sam.troy.value+"\n";
}
</script>
</head>
<body>
<form name="sam">
<textarea cols=13 rows=12 name="jaws"></textarea>
<input type="text" maxlength="25" name="troy">
<button onclick="fred()">go</button>
</body>
</html>


So what do I got to do to save the strings to a file, so the users post stay until I erase them, as being the mod. or they get overwritten, etc.?

I appreciate the help.

Code One

Adrian Girling
11-15-2003, 04:46 PM
Well, I've been planning to do something like this myself for a while now, one of my clients has been asking if its possible, so I'll write something over the weekend and, once I get it working, I'll post the code for you.

If you don't hear in a day or so, its cos I've failed miserably and will be too ashamed to admit:rolleyes:

Adrian

Code One
11-15-2003, 04:51 PM
that would be great!! Thanks so much.

Code One

SA Heat
11-15-2003, 10:21 PM
I too would love to hear if you get something like that to work, Adrian, If ya can't get it to work maybe you can post what ya have tried and some of us can work out the kinks and maybe everyone working together can come up with something valuable to us all. Good luck with it !:)

Adrian Girling
11-16-2003, 03:25 AM
We need to keep our heads down and walk in the shadows here, I think we are in the wrong forum.

This is the guts of the script in php. You can see it in action at www.sensualgfescort.co.uk/guestbook/guestbook.php. Please don't look at the rest of the site, even if you are over 18. The content is tame enough, but I'm afraid you'll see my hopeless html scripting.

If your server handles php, put this code in the body of an html page and save it with a .php extension and it should work. You will need to upload a messages.txt file too (empty to start with) and to set the conditions on it to enable users to write to it.

If this is not clear, I'm happy to explain, but if you are familiar with php you will undersatand and be able to criticize it immediately.

Here goes.

<form name="form1" method="post" action="guestbook.php" target="main">

<p>Please write a message here:
<textarea name="new_message" rows="4" cols="50"></textarea>
<br />

<P><input type="submit" value="Submit Message">
<INPUT TYPE="reset" VALUE="Clear and Start Again">

</form>

<?php

if($new_message != null)
{
$new_message .= "<br /><hr />";
echo("$new_message");
}

$filename = "messages.txt";
$file = fopen( $filename, "r" );
$filesize = filesize( $filename );
$all_messages = fread( $file, $filesize );
fclose( $file );

echo ("$all_messages");

$new_message .= "$all_messages";
$all_messages = $new_message;

$file = fopen($filename, "w");
fwrite($file, $all_messages);
fclose($file);

?>

Thats it. I need to make some tweaks and add an extra box so users can enter e-mail address, etc. Any suggestions for improvement most welcome.

Adrian