VBS Chat CGI |
Writing a chat program requires four basic things. Things that are
amazingly
common to most CGIs. First, you have to display data. Second, you have
to generate a form allowing the user to input new data. Third, you have
to accept and process submitted data. Fourth, of course, you have to
have
some kind of data store to keep your data in.
Generally speaking, I make the default action for CGIs (what happens
if you hit the CGI with no arguments) a simple display action. So if
this
code finds no arguments, it displays the existing chat comments (shown
here):
If the user presses the "Add Your Comment" button, I need to detect
that condition and send a blank "Add Your Comment" form. Now, I could
have
done that by setting a special value, but I picked a simpler route.
Step
aside with me into the future for a moment. What happens if the user is
adding a comment but forgets to fill in a required field (like his name
or comment)? Well, the appropriate action is to make the user resubmit
the form. Generally you scold the user first, and if you are nice, you
send a form with the previously-entered data as a starting point. But
this
is just a simple demo! So all I do is give stupid users a new blank
form.
So... back to here and now. When the user hits the "Add Your Comment"
button,
I just submit a form with no data in the required fields. My program
responds
by sending a new blank form. Simple. The error-handling and form
request
are the same. Here's the add form -- and you can see the empty fields
in
the URL:
As far as the data store required, I use an Access MDB file. No, you
don't need to have Access installed! The "Jet" database engine used by
Access is part of most recent operating systems and is a free download
just in case you don't have it. And since I use DAO (the native way of
talking to Jet), I can create a completely new database as needed. So
the only distributable is the script itself. Because the script
creates the database, whatever account the script is running under will
certainly have rights to the file it created! There's no worrying about
multiple files, configuration, or file permissions.
Download the complete vbs code here.
Lost? Look at the site map.
Bad links? Questions? Send me mail.