admin
06-04-2003, 04:01 PM
Write Form responses to a text file and then read it back... all on the same page!
This script assumes you have created a seperate page which posts form responses to this page here:
<%
' Counts number of items in the Form collection (not necessary)
Response.Write "Number of items: " & Request.Form.Count & "<br><p>"
' Create instance of FileSystemObject
Set objFSO = Server.CreateObject( "Scripting.FileSystemObject" )
' Create the text file
Set myFile = objFSO.CreateTextFile(Server.MapPath("/Wherever/Whatever.txt"))
' Write this line to the text file created above
myFile.WriteLine "This text file was created on " & Date
' Write each Form key and value to the text file created above
For x = 1 to Request.Form.Count
myFile.WriteLine Request.Form.Key(x) & " = " & Request.Form.Item(x)
Next
myFile.Close
' Display the text file created above
Set DisplayText = objFSO.OpenTextFile(Server.MapPath("/Wherever/Whatever.txt"))
While Not DisplayText.AtEndOfStream
Response.Write(DisplayText.ReadLine) & "<br>"
Wend
DisplayText.Close
' Close objects
Set DisplayText = Nothing
Set objFSO = Nothing
%>
By Marc W.
This script assumes you have created a seperate page which posts form responses to this page here:
<%
' Counts number of items in the Form collection (not necessary)
Response.Write "Number of items: " & Request.Form.Count & "<br><p>"
' Create instance of FileSystemObject
Set objFSO = Server.CreateObject( "Scripting.FileSystemObject" )
' Create the text file
Set myFile = objFSO.CreateTextFile(Server.MapPath("/Wherever/Whatever.txt"))
' Write this line to the text file created above
myFile.WriteLine "This text file was created on " & Date
' Write each Form key and value to the text file created above
For x = 1 to Request.Form.Count
myFile.WriteLine Request.Form.Key(x) & " = " & Request.Form.Item(x)
Next
myFile.Close
' Display the text file created above
Set DisplayText = objFSO.OpenTextFile(Server.MapPath("/Wherever/Whatever.txt"))
While Not DisplayText.AtEndOfStream
Response.Write(DisplayText.ReadLine) & "<br>"
Wend
DisplayText.Close
' Close objects
Set DisplayText = Nothing
Set objFSO = Nothing
%>
By Marc W.