Home

ASP ADVANCED

It's a good idea to include a feedback page on your Web site.  A feedback page allows users to comment on problems, suggest improvements, and provide compliments.  You can use this information to intelligently adapt your site to the requirements of your audience.

The simplest way to create a feedback page is to use in HTML form that sends the feedback to an e-mail account.  For example, the following HTML page e-mails the information entered into a form to the webmaster@yoursite.com e-mail account:

<HTML>
<HEAD><TITLE> Feedback </TITLE></HEAD>
<BODY>
<H2> Please enter any suggestions for improving this web site in the form below: </H2>
<FORM ACTION="MAILTO:webmaster@yoursite.com">
<TEXTAREA NAME="Feedback" COLS=30 ROWS=10 WRAP=VIRTUAL></TEXTAREA>
<P><INPUT TYPE="SUBMIT" VALUE="Submit Feedback">
</FORM>
</BODY>
</HTML>

This feedback form would work fine for small Web sites.  All feedback is sent to a single e-mail account.  However, if your Web site has multiple administrators, you may want all the administrators to be able to view the feedback.  Also, you may want to store any feedback so it can be retrieved and analyzed in the future.  In that case, you should store user feedback in a database table.

This section describes how to use the ADO to store and retrieve user feedback.  You learn how to create an advanced feedback form.  The following table and files are used in this project:

  • Feedback table.  A SQL Server database table used to store user feedback.
  • Feedback page.  An HTML page where users enter feedback on your Web site.
  • Acknowledgment page.  An Active Server Page that thanks the user for entering feedback and stores the feedback in the database.
  • Display page.  An Active Server Page that displays user feedback by retrieving it from the database.

Creating the Feedback Table

The Feedback table has four columns: one column each for the e-mail address, the IP address, the date the feedback was created, and the contents of the feedback.  To create this table, launch ISQL/w from the Microsoft SQL Server program group.  Next, enter the following text in the query window and execute it:

CREATE TABLE Feedback (Feed_Email VARCHAR(50),
Feed_IP VARCHAR(20),
Feed_Date DATETIME Default GetDATE( ),
Feed_Contents TEXT)

Creating the Feedback Page

The Feedback page is a normal HTML page (see Figure Below).  It contains a text field where users can enter their e-mail address and a text area where users can enter feedback.  It also has a single submit button for submitting the feedback.  When the feedback is submitted, the user is brought to the Acknowledgment page.  Listing below shows the script for the Feedback page.

The Feedback Page

The Feedback Page

Listing Script for feedback.htm.

<HTML>
<HEAD><TITLE> Feedback </TITLE></HEAD>
<BODY BGCOLOR=#FFFFFF>
<H2> Please enter any suggestions for improving this web site in the form below: </H2>
<FORM METHOD="POST" ACTION="acknowledge.asp">
Please enter your email address:
<BR><INPUT NAME="Email" TYPE="TEXT" SIZE="30" MAXLENGTH="50">
<P><TEXTAREA NAME="Contents" COLS=30 ROWS=10 WRAP=VIRTUAL></TEXTAREA>
<P><INPUT TYPE="SUBMIT" VALUE="Submit Feedback">
</FORM>
</BODY>
</HTML>

Creating the Acknowledgment Page

The Acknowledgment page has a dual purpose.  First, it's used to thank the user for providing feedback. Second, and more importantly, this page is used to actually store the feedback in the Feedback table.  The feedback is added to this table with the SQL INSERT statement, as shown in Listing below.

Listing Script for acknowledge.asp.

<%
'   Retrieve form fields into variables
Email=Replace(Request.Form("Email") ," ' ", " ' ' ")
Contents=Replace(Request.Form("Contents") ," ' ", " ' ' ")

'   Check for empty content
IF Email=" " THEN Email="Unknown"
IF Contents=" " THEN Contents="None" 

'   Grab the user's IP address
UserIP=Request.ServerVariables("REMOTE_ADDR")

'   Create the SQL command string
MYSQL="INSERT Feedback (Feed_Email, Feed_IP, Feed_Contents)
VALUES (' "&Email&" ', ' "&UserIP&" ', ' "&Contents&" ')"

'   Insert the form data into the Feedback table
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "FILEDSN=d:\Program Files\Common Files\ODBC\Data Sources\MyData.dsn"
MyConn.Execute MYSQL
%>
<HTML>
<HEAD><TITLE> Thank You </TITLE></HEAD>
<BODY>
<H2> Thank you for your suggestions! </H2>
</BODY>
</HTML>

Creating the Display Page

The Display page is used to display the feedback that users have entered. The feedback is retrieved from the Feedback table.  Because a Web site may receive thousands of feedback messages, the Display page doesn't show all the records from this table.  Only the last 25 feedback messages entered are displayed.  This is accomplished by using the MaxRecords property of the Recordset object.

To show the contents of each feedback message, a text area is used.  The advantage of using text they area is that they have scroll bars.  If a really long feedback message is entered, it won't dominate the Display page.  Listing below shows the script for display.asp.

Listing Script for display.asp.

<%
'   Create ADO objects
Set MyConn=Server.CreateObject("ADODB.Connection")
Set RS=Server.CreateObject("ADODB.RecordSet")
MyConn.Open "FILEDSN=d:\Program Files\Common Files\ODBC\Data Sources\MyData.dsn"

'   Set the maximum number of records to return RS.MaxRecords=25

'   Retrieve the records
RS.Open "SELECT * FROM Feedback ORDER BY Feed_Date DESC", MyConn
%>

<HTML>
<HEAD><TITLE>Display Feedback</TITLE></HEAD>
<BODY>
<FORM>
<%
'   Display the records
WHILE NOT RS.EOF
%>
<BR><B>Date Entered:</B> <%=RS("Feed_Date")%>
<BR><B>Email:</B> <%=RS("Feed_Email")%>
<BR><B>IP Address: </B><%=RS("Feed_IP")%>
<BR><TEXTAREA COLS=30 ROWS=10><%=RS("Feed_Contents")%></TEXTAREA>
<HR>
<%
RS.MoveNext
WEND
%>

</FORM>
</BODY>
</HTML>
<%
'   Close the Recordset and Connection
RS.Close
MyConn.Close
%>