BarneyRoss
11-03-2010, 12:10 PM
Hi all
I've got a HTML form which goes into a CSV file. However, I want to to have multiple forms that go to different CSV files.
The code I am using is below, I didnt write this (just amended if so it fitted how I needed it!) but I've tried my best to understand as I'm no programmer. I just need to be pointed in the right direction to how I can amend this code so that when form1 is submitted it goes to data1.csv, form 2 goes to data2.csv etc etc.
Many thanks!
<%
for each x in request.form
next
filePath = "F:\data\data1.csv"
set objFSO = server.createobject("Scripting.FileSystemObject")
if (objFSO.fileExists(filePath))=true then
set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for
' reading, true means it will create the file if not already there
fullText = trim(objTXT.readall)
lines = split(fullText, vbNewLine) 'lines is now an array, each item is
' one line of the db file.
objTXT.close
set objTXT = nothing
if trim(lines(0)) = "" then fullText = ""
else
fullText = ""
end if %>
<%
if fullText <> "" then 'there are already field names in the db,
' so put the new line in the same order
set objTXT = objFSO.openTextFile(filePath, 8, True) 'opens the text file for
' appending
'split the first line, which had field names into an array -fieldNames-
fieldNames = split(lines(0), ",")
'response.write "field values entered:<br>" & vbNewLine
for each x in fieldNames
if x <> "" then
nLine = nLine & request.form(x) & ","
'adds each form input to a string
end if
next
nLine = left(nLine, len(nLine)-1)
'removes trailing comma
objTXT.writeLine nLine
else 'there isn't anything in the textfile yet, so put in the field names first
set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
' writing
for each x in request.form
if lcase(x) <> "submit" then 'or you will have a "submit" field in your db
nLine = nLine & x & ","
'adds each form input name to a string which will become the first line of
'the db, the line which shows field names
response.write x & "<br>" & vbNewLine
end if
next
nLine = left(nLine, len(nLine)-1)
'remove trailing comma
objTXT.write nLine
objTXT.write vbNewLine
nLine = ""
response.write "field values entered:<br>" & vbNewLine
for each x in request.form
if lcase(x) <> "submit" then
nLine = nLine & request.form(x) & ","
'adds each form input to a string
response.write request.form(x) & "<br>" & vbNewLine
end if
next
nLine = left(nLine, len(nLine)-1)
'remove trailing comma
objTXT.write nLine
objTXT.write vbNewLine
end if
objTXT.close
%>
I've got a HTML form which goes into a CSV file. However, I want to to have multiple forms that go to different CSV files.
The code I am using is below, I didnt write this (just amended if so it fitted how I needed it!) but I've tried my best to understand as I'm no programmer. I just need to be pointed in the right direction to how I can amend this code so that when form1 is submitted it goes to data1.csv, form 2 goes to data2.csv etc etc.
Many thanks!
<%
for each x in request.form
next
filePath = "F:\data\data1.csv"
set objFSO = server.createobject("Scripting.FileSystemObject")
if (objFSO.fileExists(filePath))=true then
set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for
' reading, true means it will create the file if not already there
fullText = trim(objTXT.readall)
lines = split(fullText, vbNewLine) 'lines is now an array, each item is
' one line of the db file.
objTXT.close
set objTXT = nothing
if trim(lines(0)) = "" then fullText = ""
else
fullText = ""
end if %>
<%
if fullText <> "" then 'there are already field names in the db,
' so put the new line in the same order
set objTXT = objFSO.openTextFile(filePath, 8, True) 'opens the text file for
' appending
'split the first line, which had field names into an array -fieldNames-
fieldNames = split(lines(0), ",")
'response.write "field values entered:<br>" & vbNewLine
for each x in fieldNames
if x <> "" then
nLine = nLine & request.form(x) & ","
'adds each form input to a string
end if
next
nLine = left(nLine, len(nLine)-1)
'removes trailing comma
objTXT.writeLine nLine
else 'there isn't anything in the textfile yet, so put in the field names first
set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
' writing
for each x in request.form
if lcase(x) <> "submit" then 'or you will have a "submit" field in your db
nLine = nLine & x & ","
'adds each form input name to a string which will become the first line of
'the db, the line which shows field names
response.write x & "<br>" & vbNewLine
end if
next
nLine = left(nLine, len(nLine)-1)
'remove trailing comma
objTXT.write nLine
objTXT.write vbNewLine
nLine = ""
response.write "field values entered:<br>" & vbNewLine
for each x in request.form
if lcase(x) <> "submit" then
nLine = nLine & request.form(x) & ","
'adds each form input to a string
response.write request.form(x) & "<br>" & vbNewLine
end if
next
nLine = left(nLine, len(nLine)-1)
'remove trailing comma
objTXT.write nLine
objTXT.write vbNewLine
end if
objTXT.close
%>