Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: CGI & HTML Frames

by andreychek (Parson)
on Aug 15, 2002 at 18:34 UTC ( [id://190485]=note: print w/replies, xml ) Need Help??


in reply to CGI & HTML Frames

Another method you might be able to use is with the OpenThought Web Application Environment. OpenThought allows you to communicate with the server, and update the browser window, without actually reloading the webpage.

This would allow you to build your chat room, without needing seperate frames for each component. So, lets say we have a textarea where the chat message goes called "chatwindow", and a textarea where the user types in their message called "newtext", with an associated submit button right next to it. The way it would work then is the user would type in their new text into the "newtext" textarea, and hit submit. The page doesn't refresh -- instead, the data the user typed in is sent to the server, where you can do any amount of processing on it, and then respond back to the browser. In this case, your response might be to update the "chatwindow" textarea with the latest text, while clearing out the "newtext" textarea.

The code to make that work would look something like:
The HTML: <form name='chat'> <textarea name='chatwindow'></textarea> <br/><br/> <textarea name='newtext'></textarea> <input type='button' name='sendtext' value='Send!' onClick="parent.SendParameters('chatserver.pl','newtext', 'run_mode +=sendchatmessage')"> <br/> </form> And on the server side, we have a subroutine within a Perl script whic +h looks like: sub sendchatmessage { my $self = shift; # Retrieve the text message sent to us from the browser my $chatmsg = $self->OP->param->get_incoming('fields')->{'newtext' +}; # Perhaps we want to log all messages log_message( $chatmsg ); # Get the last 10 messages which have been sent to # the chat server (including the one we just logged) my $messages = get_last_ten(); # Prepare to send data back to the browser. # Each hash key represents a field in our HTML my $field_data = { chatwindow => $messages, # Put the last 10 messages in the cha +t window newtext => "", # Blank out the newtext field }; # Send the data back to the browser. # This puts the appropriate data into the browser, # and puts the focus on the newtext field return $self->param('OpenThought')->serialize({ fields => $field_data, focus => "newtext", }); }

In the above, the functions "log_message()" and "get_last_ten()" are hypothetical subs that you would write as part of your chat program. Everything else exists in the framework as seen.

Thats the skeleton of what you would need in order to make this work using OpenThought. See the demo app that comes with the distribution for an example of an entire working application. There's also a lot of documentation which comes with the module.

You can find OpenThought at openthought.net. The release thats out now works well, but I highly recommend grabbing the version currently in CVS. There is about to be a new release, and all sorts of neat goodies have been added and/or fixed.

Good luck!
-Eric

--
Lucy: "What happens if you practice the piano for 20 years and then end up not being rich and famous?"
Schroeder: "The joy is in the playing."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://190485]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-19 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found