Write from an html form to csv format

N

nufanvandal

Hello,

I created a web form in html, I need to create a server-side script
using ASP and embed it into the html, so that when the user clicks
submit, it sends(saves) the data from text boxes, drop-downs etc, to a
text(.txt) file on the server. It needs to be in csv format so that
they can create an excel file from it. I'm not familar with this type
of task, so any help is appreciated.

So basically two things.

How to write to a file on the server using the data from the form.
How to have the data in csv format when written.

Thanks!
 
A

Adrienne Boswell

Gazing into my crystal ball I observed (e-mail address removed) writing in
Hello,

I created a web form in html, I need to create a server-side script
using ASP and embed it into the html, so that when the user clicks
submit, it sends(saves) the data from text boxes, drop-downs etc, to a
text(.txt) file on the server. It needs to be in csv format so that
they can create an excel file from it. I'm not familar with this type
of task, so any help is appreciated.

So basically two things.

How to write to a file on the server using the data from the form.
How to have the data in csv format when written.

Thanks!

I would say to create a file on the server, then write to that file
whilst looping through the response.form collection.

dim fs,tf
dim ix, field, inputvalue
dim headers, dataline

set fs=Server.CreateObject("Scripting.FileSystemObject")
set tf=fs.CreateTextFile("c:\somefile.txt")

for ix = 1 to request.form.count
field = request.form.key(ix)
inputvalue = request.form.item(ix)
if not isnumeric(inputvalue) then
'puts quotes around text fields
inputvalue = chr(034) & inputvalue & chr(034)
end if
headers = headers & field & ", "
dataline = dataline & inputvalue & ", "
next
headers = left(headers,len(headers)-2)
dataline = left(dataline,len(dataline)-2)

'if you want the first line to contain data headers then
tf.writeline headers
'now put the data
tf.writeline dataline

tf.close
set tf=nothing
set fs=nothing

Of course, you could also just skip the csv and output directly to Excel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top