SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Adding Discussion Forums : Building your Application Inteface

Our goal is to provide you with a framework for building your own interactive and personalized community. For this reason, the sample code merely demonstrates each feature. We leave the task of clean integration with your system and backend up to you.

The basic integration point is by calling each stored procedure. By understanding the arguments required by each stored procedure, you can easily build your own custom interface. For example, we created a simple index page for listing each discussion forum. This list is displayed in the order the forums were added. Since many sites rarely define new forums this page may be better served by a statically designed page.

For example, lets look at the loop that generates the list of forums and see how the URL for viewing a forum is constructed:


while not oRS.eof
  Response.Write("<LI><A" &_ 
     HREF=""viewForum.asp?forum_id=" & oRS.fields("forum_id") & """>")
  Response.Write(oRS.fields("forum_name") & "</A>")
  if not isnull(oRS.fields("forum_update")) then
    Response.Write(" (last updated " & oRS.fields("forum_update") & ")")
  end if
  Response.Write("<BR>" & oRS.fields("forum_desc"))
  oRS.movenext
wend

Each forum URL is constructed as pageName.asp?argumentList. For reading a forum, the URL is viewForum.asp?forum_id=id. Therefore, to link directly to a particular forum you can create a link similar to the following:

<A HREF="viewForum.asp?forum_id=1">Discuss Web Development</A>

With this approach you can build any custom layout or quickly link to the discussion page from anywhere on your site.

This is the simplest integration point. This gets slightly more complex when you want to interact with the user. For example, let's imagine you are creating a new message page for a specific discussion forum. First, looking at the stored procedure for adding messages, sp_starttopic, you will notice that the stored procedure requires the forum id, a parent id if this is a reply, the user id posting the message, a message name, and the message itself.

If you were to create a form for starting new topics, you need to make sure all this information is specified and then passed back to the server. When creating the form, we use hidden fields for contextual information (forum id, etc) the user does not need to see. For example:


' BuildForm and BuildInput are helper functions for generating the FORM and INPUT tags.
Response.Write("<P>Start new topic in " & sForumName)
Response.Write(BuildForm("startTopic","post"))
Response.Write("<TABLE>")
Response.Write("<TR><TD>Forum:</TD><TD>" &_
   sForumName & "</TD></TR>")
Response.Write("<TR><TD>User Name:</TD><TD>" &_
   Session("u_name") & "</TD></TR>")
Response.Write("<TR><TD>Topic:</TD><TD>" &_
   BuildInput("text","topic_name","",20,200) & "</TD></TR>")
Response.Write("<TR><TD valign=top>Message</TD><TD>" &_
   BuildTextArea("topic_message","",10,35) & "</TD></TR>")
Response.Write("<TR><TD COLSPAN=2>" &_
   BuildInput("submit","action",ACTIONSAVE,"","") & "</TD></TR>")
Response.Write("</TABLE>")			

This creates the front-end interface. The next step is to write the interface between the user's input and the backend database. This is as simple as transferring the user's arguments into the sp_starttopic stored procedure:


if (request.form("action")=ACTIONSAVE) then
  Set oCmd = GetStoredProcedure(getConnection(),"sp_StartTopic")
  oCmd.Parameters.append oCmd.CreateParameter("forum_id", adInteger, adParamInput,10,forumID)
  oCmd.Parameters.append oCmd.CreateParameter("topic_parent", adInteger, adParamInput,10,-1)
  oCmd.Parameters.append oCmd.CreateParameter("u_id", adInteger, adParamInput,10,session("u_id"))
  oCmd.Parameters.append oCmd.CreateParameter("topic_name", adVarChar, adParamInput,200,escapeString(Request.Form("topic_name")))
  oCmd.Parameters.append oCmd.CreateParameter("topic_message", adLongVarChar, adParamInput,32000,escapeStringWithCR(Request.Form("topic_message")))
  oCmd.execute()
end if

By building your server interfaces correctly, you are essentially creating an HTTP based API for your web-site. With a little more work, you create an interface page that could allow external agents to manipulate and query your backend database. With this approach, you would most likely return structured information instead of traditional web pages. We will be pursuing this concept more in future articles.

Next, we continue by looking at the backend implementation. First we start with the database schema.