Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Related items

Exporting data to Word with Cold Fusion

How to update/edit data using Cold Fusion

Introduction to Cold Fusion

Diary of a WebObjects Developer

Building an Internet Database

My First Forum - a bulletin board application- index8

You are here: irt.org | Articles | Database | My First Forum - a bulletin board application [ previous next ]

Published on: Thursday 8th April 1999 By: Andrew Shatwell

Replying to a message - part 1

This link to this script is from openthread.cfm and as the title of the file suggests it is used for creating replies to other messages. The ID number for each article is unique so the only parameter we need to pass to this script is the article number the user is replying to.

The URL to reach this page will be similar to this: http://www.myforum.com/cfm/ReplyTo.cfm?articleID=47

<CFINCLUDE TEMPLATE="check.cfm">
<CFQUERY NAME="ArticleDetails" DATASOURCE="#MyDatabase#">
  SELECT * FROM tblArticles WHERE ArticleID = #ArticleID#
</CFQUERY>

The penultimate time I have to mention the check.cfm file!

The query obtains various details about the message the user is replying to.

<!doctype html public "-//IETF//DTD HTML 3.2//EN">
<html>
<head>
<title>My First Forum</title>
<meta name="Generator" content="HTMLed32 Version 2.0a">
<meta name="Author" content="Andrew Shatwell">

<script>
<!--
function checkFields() {
  var flag = true;
  if (document.form1.UserName.value.length == 0 || document.form1.UserEmail.value.length == 0 || document.form1.Message.value.length == 0)
  {flag = false}
  return flag;
}
// -->
</script>

</head>
<body BGCOLOR="#FFFFFF" BACKGROUND="../images/gridpaperbackground2.gif" link="#000080" vlink="#2f2f4f" onLoad="document.form1.UserName.focus()">
<div align="center">
  <IMG SRC="../images/logo2.gif" BORDER="0" ALT="My First Forum" width="469" height="64">
</div>
<p>

<b>Reply to:</b>&nbsp;
<font color="#000080"><b><CFOUTPUT>#ArticleDetails.ThreadName#</CFOUTPUT></b></font>
<p>
<form name="form1" action="reply.cfm" method="post" onSubmit="return checkFields()">
<CFOUTPUT><input type="hidden" name="oldArticle" value="#ArticleID#"></CFOUTPUT>

<table cellpadding="3">
  <tr><td NOWRAP><b>Your Name:</b></td>
     <td><input type="text" name="UserName" size="25" maxlength="25"<CFIF log eq 1> <CFOUTPUT>value="#login.FirstName# #login.Surname#"</CFOUTPUT></CFIF>></td></tr>
  <tr><td NOWRAP><b>Your Email:</b></td>
    <td><input type="text" name="UserEmail" size="30"<CFIF log eq 1> <CFOUTPUT>value="#login.Email#"</CFOUTPUT></CFIF>></td></tr>
  <tr><td NOWRAP><b>Reply:</b></td>
    <td><select name="via"><option value="board">to bulletin board<option value="email">via email</select>&nbsp;&nbsp;
    <CFOUTPUT><input type="button" value="Quote previous message" onClick="location.href='replyto.cfm?articleID=#ArticleID#&Quote=yes'"></CFOUTPUT></td></tr>
  <tr><td NOWRAP><b>Message:</b></td><td>

<!--- Begin the Cold Fusion in earnest! --->
<CFIF isDefined("url.Quote")>
  <CFSET quoted = replace(ArticleDetails.message,">>",">","all")>
  <CFSET cur = 1>
  <CFSET linelength = 0>
  <CFSET errorflag = 0>
  <CFSET offset = 44>
  <CFLOOP CONDITION="cur gt 0 and errorflag eq 0">

    <CFIF asc(mid(quoted,cur,1)) eq 13>
      <CFIF cur neq len(quoted)>
        <CFSET quoted = Insert(">",quoted,(cur+1))>
      </CFIF>
      <CFSET cur = cur + 3>
      <CFSET linelength = 0>

    <CFELSE>
      <CFLOOP CONDITION="linelength gte offset AND errorflag eq 0">
        <CFIF asc(mid(quoted,cur,1)) gte 65 and asc(mid(quoted,cur,1)) lte 123>
          <CFSET cur = cur - 1>
          <CFIF cur lt 1><CFSET errorflag=1> <CFBREAK></CFIF>
        <CFELSE>
          <CFIF cur gt len(quoted)><CFSET errorflag = 1> <CFBREAK></CFIF>
          <CFSET quoted = Insert(chr(13)&chr(10)&">", quoted, cur)>
          <CFSET linelength=0>
          <CFSET cur = cur + 4>
        </CFIF>
      </CFLOOP>
      <CFIF errorflag eq 1><CFBREAK></CFIF>
      <CFSET cur = cur + 1>
      <CFSET linelength = linelength + 1>
    </CFIF>
    <CFIF cur gt len(quoted)><CFBREAK></CFIF>
  </CFLOOP>

  <textarea name="Message" cols="45" rows="10" WRAP="virtual"><CFOUTPUT>>#quoted#</CFOUTPUT>
<!--- End of Cold Fusion mass! --->

<CFELSE>
  <textarea name="Message" cols="45" rows="10" WRAP="virtual">
</CFIF></textarea></td></tr>
</table>

<div align="center">
<input type="checkbox" name="notify" VALUE="true">
<font color="#000080" size="-1">&nbsp;Check here to be notified by email whenever someone replies to this thread.</font>
<p><input type="submit" value="Submit Message">&nbsp;<CFOUTPUT><input type="Button" value="Cancel" onClick="location.href='openthread.cfm?forum=#ArticleDetails.GroupID#&ThreadId=#ArticleDetails.ThreadID#'"></CFOUTPUT>
</div>

<input type="hidden" name="UserName_required">
<input type="hidden" name="UserEmail_required">
<input type="hidden" name="Message_required">

</form>
</body>
</html>

You might have noticed that this script is similar to that used in the Postnew.cfm script. That is, with two exceptions. Firstly, there is no subject field and secondly, there is a mass of Cold Fusion tags in the middle of the form.

When the Quote previous message button is pressed, this script is reloaded with quote=yes appended to the URL.

We test for this parameter using <CFIF isDefined("url.Quote")> and if it exists run the script that copies the previous article into the message textbox.

Keeping with the tradition of many newsreaders, a quoted article has the > character inserted at the beginning of each line.

To avoid the quoted text running off the side of the message textbox it is formatted so each line has a maximum of 44 characters. It would be straightforward to parse a passage of text and insert a carriage return and '>' sign every 45 characters. However, this would result in splitting words over two lines and make the quoted passage difficult to read.

This code starts by moving through the quoted article one character at a time. The current position of the cursor is held in the variable cur.

If the cursor reaches a carriage return then a ">" character is inserted and the cursor moves on.

If the cursor moves forward 44 characters (the value of offset) without encountering a carriage return then the script needs to add a line break. However, we do not want to split words over two lines.

If the 44th character on a line is an alphanumerical character, we check the 43rd position, and then the 42nd, and so on until we find a space. Upon success, we insert a carriage return and ">" character. The cursor then continues through the article one character at a time until it finds another carriage return or it reaches the limit of 44 characters again.

The contents of the form are posted to the reply.cfm file.

Back to Posting a message - part 2, or forward to Replying to a message - part 2

Related items

Exporting data to Word with Cold Fusion

How to update/edit data using Cold Fusion

Introduction to Cold Fusion

Diary of a WebObjects Developer

Building an Internet Database

©2018 Martin Webb