Creating Bulletin Boards
Creating a simple CGI message board
The HTML Templates
The Bulletin Board Script
Displaying the Message List
Displaying Messages
Adding New Messages
Adding Replies
Expiring Messages
The Complete Bulletin Board Script


[Previous] [Next]


The HTML Templates


The first Web page the user sees on your movie bulletin board is a list of headers from all posted messages. For this bulletin board, the header for a single message contains the subject field, the posting user's name, and the date the message was posted. The subject of each message is an HTML link that, when clicked, loads an HTML page containing the entire message. The messages are listed in the order in which they were received, with the most recent at the bottom. Replies to messages are also listed in the order in which they are received, but are indented under the message they are in response to. For example, in Figure 1 the messages are the postings by Ralph Sams and Diane Nelson. The postings by Randy Stephens and Mark Adams are replies to the message posted by Ralph Sams. All the other messages are replies to the posting by Diane Nelson.

At the bottom of the list of message headers will be an HTML form to let the user viewing your Web page post a new message. This form is for new messages only. If your users want to reply to a message, they need to use a different form. The HTML code for this form, along with the rest of the HTML code for the first template file, is shown in Listing 1. The file name for this template file is message-list.tmpl. (Name the file m-list.tml if your system restricts you to an eight-character file name and a three-character extension.) Figure 1 already showed what the message list looks like. Figure 9.2 shows how Netscape displays the new message form that the user uses to post a new message to your bulletin board. Figure s 9.1 and Figure 2 both display the same HTML page; Figure 2 is the bottom part of the page whereas Figure 1 is the top part of the page. Notice that the message headers are added between the two <HR> tags. You develop the Perl code for doing this in the next section, "Displaying the Message List."

Listing 1: The message-list.tmpl File
<HTML>
 <HEAD>
 <TITLE>The Message Board - All Messages</TITLE>
 </HEAD>
 <BODY>
 <H1>The Message Board</H1>
 Welcome to the message board. To read a message, click on the subject
 of the message you want to read. You can add a new message by using
 the <A HREF="#form">form</A> at the bottom of this page. To add a
 reply to a message, first view the message you want to reply to, and
 then use the reply form at the end of that page.
 <HR>
 <HR>
 <A NAME="form"><H1>New Message Form</H1></A>
 Use this form to add a new message to the message board. Do not use
 this form if you want to reply to one of the previous messages.
 <FORM METHOD=POST ACTION="/cgi-bin/board.pl">
 <TABLE>
 <TR>
 <TD><B>Name</B></TD>
 <TD><INPUT NAME="name" SIZE=42></TD>
 </TR>
 <TR>
 <TD><B>E-mail Address</B></TD>
 <TD><INPUT NAME="email" SIZE=42></TD>
 </TR>
 <TR>
 <TD><B>Subject</B></TD>
 <TD><INPUT NAME="subject" SIZE=42></TD>
 </TR>
 <TR>
 <TD COLSPAN=2><B>Comments</B><BR><TEXTAREA NAME="comments" ROWS=5
 COLS=38></TEXTAREA></TD>
 </TR>
 <TR>
 <TD COLSPAN=2><INPUT TYPE="submit" NAME="submit" VALUE="Post Message">
 <INPUT TYPE="reset" VALUE="Clear"></TD>
 </TR>
 </TABLE>
 </FORM>
 </BODY>
 </HTML>






Figure 2: The New Message form

You need another HTML template file for displaying an entire message to the user. The message list displays only the header information for each message. To see the entire message, the user needs to click on the message subject. This link loads a page that displays the entire message along with a reply form for posting a new reply. Because each message is stored in a separate text file, your bulletin board script can easily display the selected message by reading in the contents of the text file, inserting it into a template of HTML code, and outputting the results to the user's Web browser. Listing 2 contains the HTML code for displaying the messages and replies. Notice how the lines


 <TITLE>The Message Board - XXXX</TITLE>
 <TD><INPUT NAME="subject" VALUE="YYYY" SIZE=42></TD>


contain the strings XXXX and YYYY. These are placeholders for real data that will be inserted by your bulletin board script. You will develop the code for displaying messages and replies in the section "Displaying Messages" later in this article. Figure 3 shows how the Netscape browser displays a sample message and Figure 4 shows the Reply form in which the user enters the data for a new reply. Like Figure s 9.1 and 9.2, Figure s 9.3 and 9.4 are two parts of the same HTML page.
Listing 2: The message.tmpl File
<HTML>
 <HEAD>
 <TITLE>The Message Board - XXXX</TITLE>
 </HEAD>
 <BODY>
 <HR>
 <A NAME="form"><H1>Reply Form</H1></A>
 Use this form to add a reply under this subject heading. Do not use
 this form if you want to post a new message.
 <FORM METHOD=POST ACTION="/cgi-bin/board.pl">
 <TABLE>
 <TR>
 <TD><B>Name</B></TD>
 <TD><INPUT NAME="name" SIZE=42></TD>
 </TR>
 <TR>
 <TD><B>E-mail Address</B></TD>
 <TD><INPUT NAME="email" SIZE=42></TD>
 </TR>
 <TR>
 <TD><B>Subject</B></TD>
 <TD><INPUT NAME="subject" VALUE="YYYY" SIZE=42></TD>
 </TR>
 <TR>
 <TD COLSPAN=2><B>Comments</B><BR><TEXTAREA NAME="comments" ROWS=5
 COLS=38></TEXTAREA></TD>
 </TR>
 <TR>
 <TD COLSPAN=2><INPUT TYPE=hidden NAME="list" VALUE="ZZZZ"><INPUT
 TYPE="submit" NAME="submit" VALUE="Post Reply"> <INPUT TYPE="reset"
 VALUE="Clear"></TD>
 </TR>
 </TABLE>
 </FORM>
 </BODY>
 </HTML>






Figure 3: A sample message



Figure 4: The Reply form


[Previous] [Next]