 Inside Technique : Popup Surveys : Server-side Processing
We track the survey responses in a delimited text file. This is the simplest solution that requires minimal work on the server. Since we use
a delimited text file, the results can be easily imported into a database allowing you to compile and track your survey results.
The server-side script below is written in VBScript. VBScript currently offers better error handling than JavaScript on the server through
the on error statement. Also, when examining the script below, the getForm() and WriteToLogFiile() functions are generic and can be used with any
forms that are posted to the server.
<SCRIPT LANGUAGE="VBScript" RunAt=server>
function getForm()
logText=""
For Each Item in Request.Form
logText=logText+""""+request.form(item)+"""|"
Next
getForm = logText
end Function
function WriteToLogFile(strMessage)
On error resume next
WriteToLogFile = False
Set fs= CreateObject("Scripting.FileSystemObject")
' Update the this path to the absolute path on your server
Set objLogFile = fs.OpenTextFile("c:\myserver\results.txt", 8, False)
objLogFile.WriteLine(""""+(Request.ServerVariables("HTTP_USER_AGENT"))+"""|"+strmessage)
objLogFile.Close()
end function
writeToLogFile(getForm())
' Store cookie
Response.Cookies(request.form("questionID")) = "true"
Response.Cookies(request.form("questionID")).Expires = #1/1/2000#
' In the response close the window. If window does not close
' a default message is displayed.
Response.write("<" & "SCRIPT>window.close()</" & "SCRIPT>")
Response.write("Thank you for taking part in our survey.")
</SCRIPT>
The WriteToLogFile appends the survey response plus the user agent string to the specified text file. Each field in the text flle is
delimited by a bar "|" making it easy to import into a database. Below demonstrates three survey responses:
"Mozilla/4.04 [en] (WinNT; I ;Nav)"|"EveryDay"|"q1"|
"Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)"|"CoupleDay"|"q1"|
"Mozilla/3.04 (WinNT; I)"|"Techniques"|"q2"|
The first field is the user agent string. This information is automatically provided as part
of each page request. The second field is the user's response. This value corresponds to the first array
entry for a survey response (eg., pageAnswers[1] = new Array("EveryDay","Every Day")). The last
field corresponds to the question id. This allows you to track multiple survey questions in a single file using a single
submit.asp. If each survey needs to be in a separate file, you would either need to duplicate the submit.asp multiple
times, one for each file, or include code in submit.asp that opens the correct file based on the survey id.
This concludes our introduction to our framework for creating popup surveys. Please let us know if you improve or enhance
our approach in our discussion forums..
Discuss and Rate this Article© 1997-2000 InsideDHTML.com, LLC. All rights reserved. |