473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

html form using asp to save csv file on a server

I know this question was already covered, but it was covered way beyond my ability. They just posted the code, but i am not realy familiar with anything except html and action script. Can you guys help me.
I have this html form and i need it to submit to a csv file. Where should i begin? Here's a link to the form.

http://www.wzzo.com/pages/formSurvey/survey.html

Thanks in advance. I would be happy to answer any action script questions you may have.
Jul 11 '07 #1
67 20483
jhardman
3,406 Expert 2GB
the only thing you need to do is put the relative path of the csv file as the "action" attribute of the form tag. your form currently says:[html]<form name="form1" method="post" action="">[/html]it should say::[html]<form name="form1" method="post" action="/myCsvFolder/myFormHandler.csv">[/html]Let me know if this answers your question.

Jared
Jul 12 '07 #2
What does my formHandler.csv have to consist of? Please don't be afraid to over explain. I constructed the form through a tutorial. It told me to make a .txt doc with my field names and percent signs (looks exactly like this)

%%_q1,%%_q2,%%_q3,%%_q4,%%_q5,%%_q6,%%_q7,%%_q8,%% comments,

to show the comp how i want my csv file written. Thanks for the help so far and thanks in advance for any additional help. Do i need to create a separate directory for the csv files? Are all the submissions going to be stored in one file or multiple files? After creating that .csv form handler is there anything else i have to do?
Jul 12 '07 #3
jhardman
3,406 Expert 2GB
What does my formHandler.csv have to consist of? Please don't be afraid to over explain. I constructed the form through a tutorial. It told me to make a .txt doc with my field names and percent signs (looks exactly like this)

%%_q1,%%_q2,%%_q3,%%_q4,%%_q5,%%_q6,%%_q7,%%_q8,%% comments,

to show the comp how i want my csv file written. Thanks for the help so far and thanks in advance for any additional help. Do i need to create a separate directory for the csv files? Are all the submissions going to be stored in one file or multiple files? After creating that .csv form handler is there anything else i have to do?
ahh. It looks like I rushed in a little too fast with my last answer. I assumed you had some form handler already in place which had the file extension ".csv" This didn't ring a bell at the time, but now if I understand you, you don't have a form handler in place, but you just want to save the data to a comma-separated variable file (plain text database). Is this right?

If so, then I take back what I said before. You will need to make a form handler first, but this is pretty easy. You also need to make a plain text file with a ".csv" extension but you can just leave it blank. Putting it in its own folder is a matter of personal preference, but I guess it can also affect security, so yeah, I would put it in its own folder.

But first, make this form handler:
Expand|Select|Wrap|Line Numbers
  1. dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & vbNewLine
  4. next
Save this file with a convenient and easy to remember name with ".asp" file extension. put this file name as the "action" attribute of the original form tag and test it. This will not save the data anywhere (this is a very simple form handler) all it does is display the form data.

After you do that, respond here, and I will look up the code for saving the file (this isn't something I've ever bothered to memorize, although I do use it often enough)

Jared
Jul 12 '07 #4
Thanx. Done and done. What's next brother?
Jul 13 '07 #5
jhardman
3,406 Expert 2GB
Thanx. Done and done. What's next brother?
OK, the form handler needs to make a fileSystemObject (fso), then it needs to use the fso to make a textStream which will first, read the text file, then save plain text to the file. Watch this:
Expand|Select|Wrap|Line Numbers
  1. dim objFSO, objTXT, lines, newRecord, filePath, fieldNames, x
  2.  
  3. filePath = "C:\inetpub\csvFiles\myCSVdb.csv" 'needs absolute path of file
  4. set objFSO = server.createobject("Scripting.FileSystemObject")
  5.  
  6. set objTXT = objFSO.openTextFile(filePath, 1, True) 'opens a text file for
  7. ' reading, true means it will create the file if not already there
  8.  
  9. if objTXT.readall <> "" then 'file already existed, is not blank
  10.    lines = split(objTXT.readall, vbNewLine) 'lines is now an array, each item is
  11.        ' one line of the file
  12.    fieldNames = split(lines(0), ",") 'now we have a list of the fields in the db.
  13. end if
  14.  
  15. objTXT.close
  16.  
  17. set objTXT = nothing
  18.  
  19. set objTXT = objFSO.openTextFile(filePath, 8, True) 'opens the text file for 
  20.    '  appending %>
  21. <h1>added to the db:</h1>
  22.  
  23. <%
  24. if trim(fieldNames(1)) <> "" then 'there are already field names in the db,
  25.    ' so put the new line in the same order
  26.    for each x in fieldNames
  27.       objTXT.write request.form(x) & ","  'adds each form input to the txtfile
  28.       'in the order of the fields in the db
  29.       response.write request.form(x) & "<br>" & vbNewLine
  30.    next
  31.    objTXT.write vbNewLine
  32. else 'there isn't anything in the textfile yet, so put in the field names first
  33.    for each x in request.form
  34.       objTXT.write x & ","
  35.       response.write x & "<br>" & vbNewLine
  36.    next
  37.    objTXT.write vbNewLine
  38.  
  39.    for each x in request.form
  40.       objTXT.write request.form(x) & ","
  41.       response.write request.form(x) & "<br>" & vbNewLine
  42.    next
  43.    objTXT.write vbNewLine
  44. end if
  45. objTXT.close
Jul 13 '07 #6
Thanks a million for your help
Jul 16 '07 #7
silvito
12
Hello,

i have tried this for myself but i can't get it to work. i have creted a form handler file with the follow code

dim x
for each x in request.form
response.write x & ": " & request.form(x) & vbNewLine
next


Like you mention at first and tried it and i get a page diplaying that code. (i don't if that is what it should do when testing the handler code)

then this is the part that gets me confussed do i add the rest of the code in that same handler file or do i create another file and place that code there?

i tried it by placeing it in the same handler file but nothing gets saves in the .csv file

What am i doing wrong!
Please help!
Jul 27 '07 #8
jhardman
3,406 Expert 2GB
Did you put the code in ASP tags?:
Expand|Select|Wrap|Line Numbers
  1. <% dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & vbNewLine
  4. next %>
Did you save it as .asp?

If you did both of these than it is likely that you do not have ASP supported, or maybe just not turned on.

Jared
Jul 27 '07 #9
silvito
12
Did you put the code in ASP tags?:
Expand|Select|Wrap|Line Numbers
  1. <% dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & vbNewLine
  4. next %>
Did you save it as .asp?

If you did both of these than it is likely that you do not have ASP supported, or maybe just not turned on.

Jared

so i can put all of the code you given us in the same handler page? Cause i did that and i get the HTTP 500 internal server error.

I added this after the three line code you provided

<%dim objFSO, objTXT, lines, newRecord, filePath, fieldNames, x

filePath = "http://www.domain.com/test.csv" 'needs absolute path of file
set objFSO = server.createobject("Scripting.FileSystemObject")

set objTXT = objFSO.openTextFile(filePath, 1, True) 'opens a text file for
' reading, true means it will create the file if not already there

if objTXT.readall <> "" then 'file already existed, is not blank
lines = split(objTXT.readall, vbNewLine) 'lines is now an array, each item is
' one line of the file
fieldNames = split(lines(0), ",") 'now we have a list of the fields in the db.
end if

objTXT.close

set objTXT = nothing

set objTXT = objFSO.openTextFile(filePath, 8, True) 'opens the text file for
' appending

if trim(fieldNames(1)) <> "" then 'there are already field names in the db,
' so put the new line in the same order
for each x in fieldNames
objTXT.write request.form(x) & "," 'adds each form input to the txtfile
'in the order of the fields in the db
response.write request.form(x) & "<br>" & vbNewLine
next
objTXT.write vbNewLine
else 'there isn't anything in the textfile yet, so put in the field names first
for each x in request.form
objTXT.write x & ","
response.write x & "<br>" & vbNewLine
next
objTXT.write vbNewLine

for each x in request.form
objTXT.write request.form(x) & ","
response.write request.form(x) & "<br>" & vbNewLine
next
objTXT.write vbNewLine
end if
objTXT.close%>


Does this code go in the same file as the handler code or does it have to go in a separate .asp file. this portion which write the info to the csv file is giving me trouble. does the csv file need special permission? if so what would it be?
Please provide in detail what i need to do so that it work.


I greatly appreciate your time and help.
Silvito
Jul 27 '07 #10
jhardman
3,406 Expert 2GB
Silvito,

The first three-line handler code is very simple, just used to see if your asp code is recognizing the inputs. If it doesn't work then there is no reason to go on, you will have to sort it out before you try to connnect to a db. Do you have the three-liner working?

If the three-liner works, you can replace it with the second, longer code. Please note that the line that says
Expand|Select|Wrap|Line Numbers
  1. filePath = "http://www.domain.com/test.csv"
will not work. the file path needs to be the absolute path of the file you want to save on the host computer. It will not work to use a virtual path starting with "http://" It needs to start with a drive letter like I put in my example. If this is on a remote host and you don't know what the file path is, you can find it by putting this code on your page:
Expand|Select|Wrap|Line Numbers
  1. response.write request.serverVariables("path_translated")
this will write the exact file path of the current page. (Don't leave this line up on a running public page, it is a security risk.)

The CSV file will need to be in a folder for which <iuser> has modify permission. I recommend that this not be in a folder with any scripts. If this is hosted by someone else, you will need to get the host's permission to set up this folder. If you are hosting it yourself, you will need to make this new folder and edit the folder properties, allowing <iuser> (the name of the anonymous web user) to modify things in this folder. Once that is done it should work. Let me know if you have any troubles.

Jared
Jul 30 '07 #11
silvito
12
Silvito,

The first three-line handler code is very simple, just used to see if your asp code is recognizing the inputs. If it doesn't work then there is no reason to go on, you will have to sort it out before you try to connnect to a db. Do you have the three-liner working?

If the three-liner works, you can replace it with the second, longer code. Please note that the line that says
Expand|Select|Wrap|Line Numbers
  1. filePath = "http://www.domain.com/test.csv"
will not work. the file path needs to be the absolute path of the file you want to save on the host computer. It will not work to use a virtual path starting with "http://" It needs to start with a drive letter like I put in my example. If this is on a remote host and you don't know what the file path is, you can find it by putting this code on your page:
Expand|Select|Wrap|Line Numbers
  1. response.write request.serverVariables("path_translated")
this will write the exact file path of the current page. (Don't leave this line up on a running public page, it is a security risk.)

The CSV file will need to be in a folder for which <iuser> has modify permission. I recommend that this not be in a folder with any scripts. If this is hosted by someone else, you will need to get the host's permission to set up this folder. If you are hosting it yourself, you will need to make this new folder and edit the folder properties, allowing <iuser> (the name of the anonymous web user) to modify things in this folder. Once that is done it should work. Let me know if you have any troubles.

Jared

ok i have replace the code and correct the absolute path to where the csv file is located in the host server and i am getting this error on the browser:

Microsoft VBScript runtime error '800a003e'

Input past end of file

/handler.asp, line 11

i do not understand this. any thought?
Jul 30 '07 #12
jhardman
3,406 Expert 2GB
ok i have replace the code and correct the absolute path to where the csv file is located in the host server and i am getting this error on the browser:

Microsoft VBScript runtime error '800a003e'

Input past end of file

/handler.asp, line 11

i do not understand this. any thought?
which line is line 11?
Jul 30 '07 #13
silvito
12
which line is line 11?


lines = split(objTXT.readall, vbNewLine) 'lines is now an array, each item is
Jul 30 '07 #14
jhardman
3,406 Expert 2GB
lines = split(objTXT.readall, vbNewLine) 'lines is now an array, each item is
Ok, the problem is that the file is empty, but the script is still trying to read it. The line before should check this:
Expand|Select|Wrap|Line Numbers
  1. if objTXT.readall <> "" then
Replace this with
Expand|Select|Wrap|Line Numbers
  1. if trim(objTXT.readall) <> "" then
this checks a little more rigorously, but it might not fix the problem. If not, you may have to create the first line of the text file manually. If you do, it just needs to be the names of each input field separated by a comma, like this:
Expand|Select|Wrap|Line Numbers
  1. name,address,birthDate,phoneNumber,
make this in notepad, save it as a plain text file but with the file name as your .csv file. Be careful, though, notepad will still want to save this as a .txt file, so if you give it the name myDB.csv, notepad will save it as myDB.csv.txt, to avoid this you need to put the file name in quotes when you save it, like this: "myDB.csv" then notepad won't append another file extension. Let me know if this works.

Jared
Jul 30 '07 #15
silvito
12
Ok, the problem is that the file is empty, but the script is still trying to read it. The line before should check this:
Expand|Select|Wrap|Line Numbers
  1. if objTXT.readall <> "" then
Replace this with
Expand|Select|Wrap|Line Numbers
  1. if trim(objTXT.readall) <> "" then
this checks a little more rigorously, but it might not fix the problem. If not, you may have to create the first line of the text file manually. If you do, it just needs to be the names of each input field separated by a comma, like this:
Expand|Select|Wrap|Line Numbers
  1. name,address,birthDate,phoneNumber,
make this in notepad, save it as a plain text file but with the file name as your .csv file. Be careful, though, notepad will still want to save this as a .txt file, so if you give it the name myDB.csv, notepad will save it as myDB.csv.txt, to avoid this you need to put the file name in quotes when you save it, like this: "myDB.csv" then notepad won't append another file extension. Let me know if this works.

Jared

tired it all and still get the same error.
Jul 30 '07 #16
jhardman
3,406 Expert 2GB
OK, try this.
Expand|Select|Wrap|Line Numbers
  1. dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & vbNewLine
  4. next
  5.  
  6. dim objFSO, objTXT, filePath
  7.  
  8. filePath = "C:\inetpub\csvFiles\myCSVdb.csv" 'change this to whatever your 
  9. 'path is
  10. set objFSO = server.createobject("Scripting.FileSystemObject")
  11.  
  12. set objTXT = objFSO.openTextFile(filePath, 1, True)
  13.  
  14. response.write "<textarea>" & objTXT.readall & "</textarea>"
This is the original short form handler followed by code to open a text file and put the entire file in a textarea. What does it give you? Is the textarea empty? If it is empty, does it have any blank lines?

Jared
Jul 30 '07 #17
silvito
12
OK, try this.
Expand|Select|Wrap|Line Numbers
  1. dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & vbNewLine
  4. next
  5.  
  6. dim objFSO, objTXT, filePath
  7.  
  8. filePath = "C:\inetpub\csvFiles\myCSVdb.csv" 'change this to whatever your 
  9. 'path is
  10. set objFSO = server.createobject("Scripting.FileSystemObject")
  11.  
  12. set objTXT = objFSO.openTextFile(filePath, 1, True)
  13.  
  14. response.write "<textarea>" & objTXT.readall & "</textarea>"
This is the original short form handler followed by code to open a text file and put the entire file in a textarea. What does it give you? Is the textarea empty? If it is empty, does it have any blank lines?

Jared


OK it showed the what was input like before and a textarea with the names of the input that i'm using but it did not put what i have type in.


name: Silvio pino email: silvio@fakeaddress.com comments: test


This was in the textarea: name,email,comments,
Jul 30 '07 #18
jhardman
3,406 Expert 2GB
OK it showed the what was input like before and a textarea with the names of the input that i'm using but it did not put what i have type in.


name: Silvio pino email: silvio@fakeaddress.com comments: test


This was in the textarea: name,email,comments,
so this shows that the form handler can both understand the inputs and open the csv file. Next text whether it understands how you want to split up the file:
Expand|Select|Wrap|Line Numbers
  1. dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & "<br>" & vbNewLine
  4. next
  5.  
  6. dim objFSO, objTXT, filePath, lines
  7.  
  8. filePath = "C:\inetpub\csvFiles\myCSVdb.csv" 'change this to whatever your
  9. 'path is
  10. set objFSO = server.createobject("Scripting.FileSystemObject")
  11.  
  12. set objTXT = objFSO.openTextFile(filePath, 1, True)
  13.  
  14. lines = split(objTXT.readall, vbNewLine)
  15. response.write lines(0)
Jared
Jul 30 '07 #19
silvito
12
so this shows that the form handler can both understand the inputs and open the csv file. Next text whether it understands how you want to split up the file:
Expand|Select|Wrap|Line Numbers
  1. dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & "<br>" & vbNewLine
  4. next
  5.  
  6. dim objFSO, objTXT, filePath, lines
  7.  
  8. filePath = "C:\inetpub\csvFiles\myCSVdb.csv" 'change this to whatever your
  9. 'path is
  10. set objFSO = server.createobject("Scripting.FileSystemObject")
  11.  
  12. set objTXT = objFSO.openTextFile(filePath, 1, True)
  13.  
  14. lines = split(objTXT.readall, vbNewLine)
  15. response.write lines(0)
Jared



ok this displays on the browser now in four separate lines:

name: Silvio pino
email: silvio@fakemail.com
comments: test
name,email,comments,
Jul 30 '07 #20
jhardman
3,406 Expert 2GB
ok this displays on the browser now in four separate lines:

name: Silvio pino
email: silvio@fakemail.com
comments: test
name,email,comments,
good, now add the variable "fields" to the dim list, and add this to the end of the code:
Expand|Select|Wrap|Line Numbers
  1. fields = split(lines(0),",")
  2. for each x in fields
  3.    response.write x & ": " & fields(x) & "<br>" & vbNewLine
  4. next
what does this give you?

Jared
Jul 30 '07 #21
silvito
12
good, now add the variable "fields" to the dim list, and add this to the end of the code:
Expand|Select|Wrap|Line Numbers
  1. fields = split(lines(0),",")
  2. for each x in fields
  3.    response.write x & ": " & fields(x) & "<br>" & vbNewLine
  4. next
what does this give you?

Jared

Ok what do you mean by adding the variable feilds to the dim list is it the names i used for the input tags on the form? and which dim list do i add it to?

<%
dim x <------Do i add it here or
for each x in request.form
response.write x & ": " & request.form(x) & "<br>" & vbNewLine
next

dim objFSO, objTXT, filePath, lines <------Do i add it here

filePath = "D:\inetpub\fake\fake\fakedb.csv" 'change this to whatever your
'path is
set objFSO = server.createobject("Scripting.FileSystemObject")

set objTXT = objFSO.openTextFile(filePath, 1, True)

lines = split(objTXT.readall, vbNewLine)
response.write lines(0)

fields = split(lines(0),",")
for each x in fields
response.write x & ": " & fields(x) & "<br>" & vbNewLine
next
%>
Jul 31 '07 #22
jhardman
3,406 Expert 2GB
...
<------Do i add it here or
...
<------Do i add it here
...
either one. It makes no difference.

Jared
Jul 31 '07 #23
silvito
12
either one. It makes no difference.

Jared

Ok what do you mean by adding the variable feilds
Jul 31 '07 #24
jhardman
3,406 Expert 2GB
Ok what do you mean by adding the variable feilds
Expand|Select|Wrap|Line Numbers
  1. dim objFSO, objTXT, filePath, lines, fields
Jul 31 '07 #25
silvito
12
Expand|Select|Wrap|Line Numbers
  1. dim objFSO, objTXT, filePath, lines, fields

ok i am getting this error now:

full_name: Silvio pino
email: silvio@fakemail.com
comments: test
name,email,comments,
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'name'

/handler.asp, line 21


and line 21 is
response.write x & ": " & fields(x) & "<br>" & vbNewLine
Jul 31 '07 #26
jhardman
3,406 Expert 2GB
ok i am getting this error now:

full_name: Silvio pino
email: silvio@fakemail.com
comments: test
name,email,comments,
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'name'

/handler.asp, line 21


and line 21 is
response.write x & ": " & fields(x) & "<br>" & vbNewLine
OK, I checked it and you are right. I made a mistake in the code. The line should just say,
Expand|Select|Wrap|Line Numbers
  1. response.write x & "<br>" & vbNewLine
But while I was at it, I checked out the original code I had written that you said also gave you an error, and I found that the line which reads the db in the first place should not be within an if statement. So as it is written,
Expand|Select|Wrap|Line Numbers
  1. if objTXT.readall <> "" then 'file already existed, is not blank
  2.    lines = split(objTXT.readall, vbNewLine) 'lines is now an array, each item is
  3.     ' one line of the file
  4.    fieldNames = split(lines(0), ",") 'now we have a list of the fields in the db.
  5. end if
should in fact be shortened to
Expand|Select|Wrap|Line Numbers
  1. lines = split(objTXT.readall, vbNewLine) 'lines is now an array, each item is
  2.  ' one line of the file
  3. fieldNames = split(lines(0), ",") 'now we have a list of the fields in the db.
I tested it and it works fully. Try it and see.

Jared
Aug 1 '07 #27
jhardman
3,406 Expert 2GB
I just tested to see if this still worked if the script had to create a csv file in the first place. and no, it didn't work. I'll think about it for a while. If you need the script to make the csv file, I will try to solve the problem, otherwise I will leave it alone.

Jared
Aug 1 '07 #28
silvito
12
I just tested to see if this still worked if the script had to create a csv file in the first place. and no, it didn't work. I'll think about it for a while. If you need the script to make the csv file, I will try to solve the problem, otherwise I will leave it alone.

Jared

Please that would be great if you can help me out on this. I would greatly appreciate the time you spent helping me out.
Aug 1 '07 #29
cmcl79
2
Hi,

I am totally new to asp and have posted here because I think the above discussion was relevant. I have an html form which is the beginnings of upgrading a filing system. At this point I would simply like to be able to input the data and save to a specific directory on my desktop or a local server. Advantages would be being able to format the output table to fit on A4 to be simple for printing but I have no idea if this is possible.

Ultimately I am hoping to establish a database in to which myself and several colleagues will be saving data, hence using an html form in the first place.

Any help with this would be very welcome.
Aug 6 '07 #30
jhardman
3,406 Expert 2GB
Please that would be great if you can help me out on this. I would greatly appreciate the time you spent helping me out.
OK, here it is. I tested this with no db. The script makes the db and populates it on the first time, on subsequent visits any info posted is added to the db. If you want to specify an order of the fields in the db, you should make a text file like this
Expand|Select|Wrap|Line Numbers
  1. name,email,comments
and save it as the "db.csv" or whatever you like, otherwise the fields might come in a different order. If you do this though, notice that the script looks for a form input name that exactly matches the field names in the db, so make sure you spell them exactly right (I don't think it is case sensitive, but I didn't test that specifically. Anyway, it worked just fine for me just like this:
Expand|Select|Wrap|Line Numbers
  1. <% option explicit
  2.  
  3. dim objFSO, objTXT, lines, newRecord, filePath, fieldNames, x, fullText, nLine %>
  4. <h1>Form inputs posted:</h1>
  5. <%
  6.  
  7. for each x in request.form
  8.    response.write x & ": " & request.form(x) & "<br>" & vbNewLine
  9. next
  10.  
  11. 'set filepath for plain text db.  This neds to be the absolute path of file
  12. filePath = "C:\Inetpub\myCSVfiles\myCSVdb.csv"
  13. set objFSO = server.createobject("Scripting.FileSystemObject")
  14.  
  15. if (objFSO.fileExists(filePath))=true then
  16.    set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for
  17.    ' reading, true means it will create the file if not already there
  18.    fullText = trim(objTXT.readall)
  19.    lines = split(fullText, vbNewLine) 'lines is now an array, each item is
  20.     ' one line of the db file.this could now be used to list the entire db
  21.     ' table, notice next 3 commented out lines
  22.     ' for each x in lines
  23.     '    response.write lines(x)
  24.     ' next
  25.  
  26.    objTXT.close
  27.    set objTXT = nothing
  28.  
  29.    if trim(lines(0)) = "" then fullText = ""
  30. else
  31.    fullText = ""
  32. end if %>
  33. <h1>added to the db:</h1>
  34.  
  35. <%
  36. if fullText <> "" then 'there are already field names in the db,
  37.    ' so put the new line in the same order
  38.    set objTXT = objFSO.openTextFile(filePath, 8, True) 'opens the text file for
  39.    '  appending
  40.    response.write "(fields in the database: " & lines(0) & ")<br>" & vbNewLine
  41.    'split the first line, which had field names into an array -fieldNames-
  42.    fieldNames = split(lines(0), ",")
  43.  
  44.    response.write "field values entered:<br>" & vbNewLine
  45.    for each x in fieldNames
  46.       if x <> "" then
  47.          nLine = nLine & request.form(x) & "," 
  48.          'adds each form input to a string
  49.  
  50.          response.write x & ": " & request.form(x) & "<br>" & vbNewLine
  51.       end if
  52.    next
  53.    nLine = left(nLine, len(nLine)-1)
  54.    'removes trailing comma
  55.  
  56.    objTXT.writeLine nLine
  57.  
  58. else 'there isn't anything in the textfile yet, so put in the field names first
  59.    set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
  60.    '  writing
  61.    response.write "field names enterd:<br>" & vbNewLine
  62.  
  63.    for each x in request.form
  64.       if lcase(x) <> "submit" then 'or you will have a "submit" field in your db
  65.          'of course, if your submit button is named something else, that should
  66.          'be the name xcluded here
  67.  
  68.          nLine = nLine & x & ","
  69.          'adds each form input name to a string which will become th first line of
  70.          'the db, the line which shows field names
  71.  
  72.          response.write x & "<br>" & vbNewLine
  73.       end if
  74.    next
  75.    nLine = left(nLine, len(nLine)-1)
  76.    'remove trailing comma
  77.  
  78.    objTXT.write nLine
  79.    objTXT.write vbNewLine
  80.    nLine = ""
  81.  
  82.    response.write "field values entered:<br>" & vbNewLine
  83.    for each x in request.form
  84.       if lcase(x) <> "submit" then
  85.          nLine = nLine & request.form(x) & "," 
  86.          'adds each form input to a string
  87.  
  88.          response.write request.form(x) & "<br>" & vbNewLine
  89.       end if
  90.    next
  91.    nLine = left(nLine, len(nLine)-1)
  92.    'remove trailing comma
  93.  
  94.    objTXT.write nLine
  95.    objTXT.write vbNewLine
  96. end if
  97. objTXT.close
  98. %>
Jared
Aug 6 '07 #31
jhardman
3,406 Expert 2GB
Hi,

I am totally new to asp and have posted here because I think the above discussion was relevant. I have an html form which is the beginnings of upgrading a filing system. At this point I would simply like to be able to input the data and save to a specific directory on my desktop or a local server. Advantages would be being able to format the output table to fit on A4 to be simple for printing but I have no idea if this is possible.

Ultimately I am hoping to establish a database in to which myself and several colleagues will be saving data, hence using an html form in the first place.

Any help with this would be very welcome.
This example is fairly simple, try to follow along and see what the script is doing. To make it work, just save this script as "handler.asp" and make it the value of the action attribute of the HTML form you are using. [html]<form method="post" action="handler.asp">[/html] All this data is sent to a plain text file in a format that is easily imported into MS excel or a db, or even read by some db drivers. There are some drawback to doing it this way, but it keeps thing very simple. Try it out and see if you like it.

Jared
Aug 6 '07 #32
cmcl79
2
Thankyou very much. That pretty much does what I wanted ... I really appreciate your help!

Carina
Aug 7 '07 #33
silvito
12
Thank You so Much You are the Awesome Thanks
Aug 7 '07 #34
Hello,

I'm hoping you can help me with my form. I used some of the script you gave in this discussion but it's not working for me for some reason. Can you check this out and tell me what you think? http://www.rwgarcia.com/forms/form.html When I test the form it just goes to the formhandler.asp page.

Any help would be VERY greatly appreciated!

Kam
Sep 7 '07 #35
jhardman
3,406 Expert 2GB
Kam,

Ah, yes. The problem is that you tried to put the code in a WYSIWYG editor, an editor that tries to make exactly what you put on the screen show up on the web page. Instead, save this text in notepad or wordPad or textWrangler or some such. This should be either a plain text editor designed to manipulate words without making them look fancy, or a code editor. Either way, the editor should not attempt to alter this code. (btw, you will need to remove the line numbers, this website adds that to the code as do some code editors, they are just there for reference and shouldn't be saved).

When you go to save if you use notePad or wordPad, you should put the name of the file in quote marks but select save as "plain text" when you get the option. Does this make sense? Try that and let me know.

Jared
Sep 7 '07 #36
Yaaayy! Thanks so much, that worked.

The only thing is, maybe I misunderstood this forum because what I wanted to do was use the csv file as a database to store collected information. I also want the user to see a thank you page after they fill out the form. Am I on the right path?

Thanks!

Kam
Sep 7 '07 #37
jhardman
3,406 Expert 2GB
Yaaayy! Thanks so much, that worked.

The only thing is, maybe I misunderstood this forum because what I wanted to do was use the csv file as a database to store collected information. I also want the user to see a thank you page after they fill out the form. Am I on the right path?

Thanks!

Kam
Yes. You can definitely add a thank you note or any valid HTML code to the bottom of the script (past the last "%>"). You can also remove the little notes about what has been saved (I just put those in for visual confirmation). You can even redirect the user to a thank you page at the bottom if you like (but I think this only works if the first page hasn't sent any information to the browser yet). The syntax for a redirect is:
Expand|Select|Wrap|Line Numbers
  1. response.redirect "thankYouPage.html"
Glad you got it working.

Jared
Sep 7 '07 #38
Great! I got the thank you page working.

Now the only problem is the info is not being saved in the cvs file. All that shows up is:

first_name, last_name, email, address1, address2, city, state, zip, country

Is something wrong in the script?

Thank you thank you thank you!!!
Sep 7 '07 #39
Actually, now there is an error when I submit the form. It says:

Scripting.FileSystemObject.1 (0x800A0035)
File not found.
/forms/formhandler.asp, line 56

This is line 56:
set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
' writing
response.write "field names enterd:<br>" & vbNewLine
Sep 7 '07 #40
jhardman
3,406 Expert 2GB
Actually, now there is an error when I submit the form. It says:

Scripting.FileSystemObject.1 (0x800A0035)
File not found.
/forms/formhandler.asp, line 56

This is line 56:
set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
' writing
response.write "field names enterd:<br>" & vbNewLine
So it went form working to only listing the field names, to not working at all? I did test it and got it to do everything I said it did. I'm not in a position to check right now, but try deleting the csv file and starting afresh, or try starting the csv file in notepad (it should just be a plain text file like you saw earlier). I will try to check it again tomorrow.

Jared
Sep 10 '07 #41
I was able to get it working okay.

Thanks for all your help. It is very greatly appreciated!

Kamala
Sep 10 '07 #42
Okay. I have more questions.

First of all, if you look at my csv file here: http://www.rwgarcia.com/forms/veggiechips.csv, there are a ton of commas being inserted. It seems like there are more everytime there is a new entry. Do you know why it's doing that? My client is using Excel to open the file and all those extra commas seem to get in the way.

Also, do you know how can password protect the csv file?

Thank you thank you thank you!!!

Kam
Sep 20 '07 #43
jhardman
3,406 Expert 2GB
Kam,

I just opened it in excel and didn't see a problem although I could see the commas in notePad. The line 53 is supposed to remove trailing commas. If you haven't altered that line than there shouldn't be a problem. It is possible that excel is adding the commas when it is used to open the file. You could definitely work out a script that searches through the saved lines and removes all fo the trailing commas. Do you need a hint to start that?

CSV files are just plain text files, so there is no built-in way to password-protect them. I don't think you can specify a user name and password when you work with the fileSystemObject. Do you just want extra security? If so, you could put all of these scripts on a folder and restrict access to that folder. When a user tries to go to this folder he should be prompted by the server to provide a password. Let me know if this helps.

Jared
Sep 20 '07 #44
Hi Jared,

Thanks for getting back to me. Yes, I could use any help you have to offer on a script to get rid of the extra commas.

As for security, I am looking into putting the file in a private file on the server. I just need to find out the url of the private directory to put into the form handler.

Kamala
Sep 21 '07 #45
jhardman
3,406 Expert 2GB
Hi Jared,

Thanks for getting back to me. Yes, I could use any help you have to offer on a script to get rid of the extra commas.

As for security, I am looking into putting the file in a private file on the server. I just need to find out the url of the private directory to put into the form handler.

Kamala
Kamala,

You see in some of my scripts above how I open the file and separate each line of the db onto its own line, right? I made this so that the first line is called lines(0), the second is called lines(1) etc. Perhaps after the end of this script you could open the file to read the same as at first. Once you have each line separated you can do this:
Expand|Select|Wrap|Line Numbers
  1. for each x in lines
  2.    do until right(trim(lines(x)),1) <> ","
  3.       lines(x) = left(trim(lines(x)), len(trim(lines(x)))-1)
  4.    loop
  5. next
then open the file to write and write each line to the file followed by the new line character. Let me know if this makes sense.

Jared
Sep 21 '07 #46
Sorry I'm a little dense and I'm new to programming. Are you able to clarify?
Sep 21 '07 #47
jhardman
3,406 Expert 2GB
Sorry I'm a little dense and I'm new to programming. Are you able to clarify?
No, I don't believe you are dense whether you are new to programming or not. Look back at post 31 where I posted the full revised code. Starting in line 16 I open the file to read and I make a series of variables (an "array") with names "lines(0)", "lines(1)", "lines(2)" etc. I suggested in my last post that you copy this exact segment of code again at the end of the script so you have an updated version of the csv file in your array "lines()". You can follow this up with the code I posted in the last post which removes all of the trailing commas from each line. You with me so far?

The only part of this that's a little bit tricky is re-saving the updated version. I believe you can figure out how to do this. I did something very similar to what you might want to do starting in line 59. In my post I showed how to write all of the form data into the file. At this point, youwill want to re-write all of the revised file whick you would have saved in the array lines(). following the open the file line (like line 59) you might say this:
Expand|Select|Wrap|Line Numbers
  1. for each x in lines
  2.    objTxt.write lines(x) & vbNewLine
  3. next
It's a good idea to close the text object after you use it, but it's not strictly required unless you are going to use it again.

I believe you can figure this out. Most of us got to where we are in our level of skills by trying it even when we weren't sure what we were doing. Sometimes we say this mantra: when in doubt, try it out.

Jared
Sep 22 '07 #48
Hi Jared,

Based on your suggestions, I added this to the end of the script:

Expand|Select|Wrap|Line Numbers
  1. set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for
  2.    ' reading, true means it will create the file if not already there
  3.    fullText = trim(objTXT.readall)
  4.    lines = split(fullText, vbNewLine) 'lines is now an array, each item is
  5.     ' one line of the db file.this could now be used to list the entire db
  6.     ' table, notice next 3 commented out lines
  7.     for each x in lines
  8.    do until right(trim(lines(x)),1) <> ","
  9.       lines(x) = left(trim(lines(x)), len(trim(lines(x)))-1)
  10.    loop
  11. next
  12.  
  13. set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
  14.    '  writing
  15.    response.write "field names enterd:<br>" & vbNewLine
  16.    for each x in lines
  17.  
  18.   objTxt.write lines(x) & vbNewLine
  19. next
  20.  

It's still not working so I'm sure I did something wrong. Any thoughts?

Thanks!

Kamala
Sep 24 '07 #49
jhardman
3,406 Expert 2GB
what error does this give you? (or does it give no error but nothing happens?)

Jared
Sep 24 '07 #50

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Manav Sharma | last post by:
Hello friends. I am using PHP(standalone program and not as Apache module) with Apache Server. My Problem is that i am not able to read the HTML form's variable.. Form' Code Snippet...
7
by: Ed Lai | last post by:
A few weeks ago I have the idea of converting XML instance data to a HTML form, using tags as the label and the resulting form can be used to edit the XML data. So I started to play around with it,...
0
by: Martin | last post by:
I'm distributing stand-alone HTML forms for users to complete and e-mail/snail-mail back to me. (For security and budget reasons, receiving the form data to a web- server is not an option.) Then...
0
by: supern | last post by:
#!c:/perl/bin/perl.exe $basedir="c:/program files/apache software foundation/apache2.2/cgi-bin"; $datafile="regstr.txt"; $name=$in{'login'}; $passwd=$in{'passwd'}; open(FH1,"+>>regstr.txt");...
0
by: sharif | last post by:
Anyone could help me out for n=my code ......I have written following code ,Here i m able to get and post the form successfuly..but after posting im not gettng proper response content... ...
7
by: jcnone | last post by:
Does anyone know how to populate form fields on a html web page (client side) with data from an Excel file (CSV) or text file. I am currently having to input data to many text fields manually. I...
0
by: brianrpsgt1 | last post by:
I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the...
1
by: mihir0288 | last post by:
I want to save HTML file that i open in web browser on my hard disk without using save file dialog box. I want to save it as html page through only code and without user interactions.
0
by: Winsly Jucar | last post by:
I want to create a program that collects data inputed by user on a webpage form, then saves it to a database located at the user's pc. My problem is: 1. is it possible to collect data from a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.