Lesson 12: Create a Chat Window

This very simple chat room script example uses 3 modes of operation. Mode 1 creates a frameset showing mode 2 on top and the default mode 0 on bottom.

Mode 2 is a data view of the chat transcript which auto refreshes every 10 seconds. Mode 0 is also the default mode which is used for the data handling and entry.

See: FRAMESET , NAMED ANCHOR , [[AUTO_REFRESH]]

Create a node and paste this following code into it’s landing page editor. Goto the node’s url address and test with browser. When testing add /?mode=1 after the address to test the frameset.

[[QUERY_STRING:mode]]
[[IF_EQUAL:$mode|"1"]]
 <frameset rows="75%,*">
 <frame src="?mode=2&#bottom" />
 <frame src="?mode=0" />
 </frameset>
[[ELSE_IF:$mode=="2"]]
 [[AUTO_REFRESH:10]]
 [[INITIALIZE:filename|"transcript.txt"]]
 [[READ_FILE:$filename|content]]
 [[PRINT:content]]
 <a name="bottom"></a>
[[ELSE]]
 [[IF_SUBMITTED]]
  [[POST:name]]
  [[POST:comment]]
  [[INITIALIZE:submitted_entry|"$name:\t $comment<br />\t\n"]]
  [[INITIALIZE:filename|"transcript.txt"]]
  [[APPEND_FILE:submitted_entry|filename]]
 [[END_IF]]
 [[FORM:#this]]
  [[INPUT:name|[[=name]]]]
  [[INPUT:comment|Enter Message]]
  [[SUBMIT:Save]]
 [[END_OF_FORM]]
[[END_IF]]

Leave a Reply