coreybryant
asked on
Dumping form to CSV
I am pretty sure it is possible, but where can I get some step by step plays on doing this for someone that knows nothing about ASP. I told someone I would help them with a form. If you could provide me with the start of the code and say one input (name) and the end of the code- I should be able add all the other inputs, right (hopefully).
Thanks!
-Corey
Thanks!
-Corey
note that above open file in append mode.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks hongjun - just a couple of questions whiel I am working thru this. When you say this create the file called report.csv, do I need to create this file or will it do it automatically? Also, not too sure what you mean by hard coding of form fields? Do you mean that it does not matter how many form fields that I have & I do not have to worry about creating the CSV file?
Thanks!
-Corey
Thanks!
-Corey
ASKER
Lets assume, on my contact form (right now):
<html>
<head>
<title>Contact</title>
</head>
<body>
<form method="Post" action="confirm.asp">
<input type="text" name="Name" size="20"></p>
<p><input type="text" name="EMail" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
And then on the confirm.asp:
<%
dim strFile, strtext
dim a
strFile="\file"
Set fs = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set a = fs.OpenTextFile(server.Map Path("\") & strFile & "report.csv", 8, true)
'this create the file called report.csv
strtext=""
for each str in Request.Form
strtext = strtext & chr(34) & str & chr(34) & ","
next
a.WriteLine(strtext)
strtext =""
for each str in Request.Form
strtext = strtext & chr(34) & Request.Form(str) & chr(34) & ","
next
a.Writeline(strtext)
'this will read the content fm a form and write into excel
%>
And then I have a report.csv in the file folder (one down). Do I need to dim the form inputs?
Thanks!
-Corey
<html>
<head>
<title>Contact</title>
</head>
<body>
<form method="Post" action="confirm.asp">
<input type="text" name="Name" size="20"></p>
<p><input type="text" name="EMail" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
And then on the confirm.asp:
<%
dim strFile, strtext
dim a
strFile="\file"
Set fs = Server.CreateObject("Scrip
Set a = fs.OpenTextFile(server.Map
'this create the file called report.csv
strtext=""
for each str in Request.Form
strtext = strtext & chr(34) & str & chr(34) & ","
next
a.WriteLine(strtext)
strtext =""
for each str in Request.Form
strtext = strtext & chr(34) & Request.Form(str) & chr(34) & ","
next
a.Writeline(strtext)
'this will read the content fm a form and write into excel
%>
And then I have a report.csv in the file folder (one down). Do I need to dim the form inputs?
Thanks!
-Corey
Yap using my second code, you need not create the .csv file. You also need not worry about the number of form fields you are going to submit because of the for loop I am using.
hongjun
hongjun
you need not dim the form inputs. Only dim the str
dim str
But if you are not using Option Explicit, you need not dim anything.
hongjun
dim str
But if you are not using Option Explicit, you need not dim anything.
hongjun
ASKER
Sounds cool. I will be needing to dim the inputs for my JMail script, but I am having a problem.... I am using :
<form method="Post" action="confirm.asp">
<input type="text" name="Name" size="20"></p>
<p><input type="text" name="EMail" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
and then in the confirm.asp:
<%
dim strFile, strtext
dim a
strFile="\file"
Set fs = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set a = fs.OpenTextFile(server.Map Path("\") & strFile & ".csv", 8, true)
'this create the file called report.csv
strtext=""
for each str in Request.Form
strtext = strtext & chr(34) & str & chr(34) & ","
next
a.WriteLine(strtext)
strtext =""
for each str in Request.Form
strtext = strtext & chr(34) & Request.Form(str) & chr(34) & ","
next
a.Writeline(strtext)
'this will read the content fm a form and write into excel
%>
and the architecture is something like this:
-www(folder)
default.asp (file)
confirm.asp (file)
--file (folder)
And I am getting this error:
Permission denied
/sites/auto/confirm.asp, line 7
I do have it checked for the read/write permissions to accept anonymous write.
Thanks!
-Corey
<form method="Post" action="confirm.asp">
<input type="text" name="Name" size="20"></p>
<p><input type="text" name="EMail" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
and then in the confirm.asp:
<%
dim strFile, strtext
dim a
strFile="\file"
Set fs = Server.CreateObject("Scrip
Set a = fs.OpenTextFile(server.Map
'this create the file called report.csv
strtext=""
for each str in Request.Form
strtext = strtext & chr(34) & str & chr(34) & ","
next
a.WriteLine(strtext)
strtext =""
for each str in Request.Form
strtext = strtext & chr(34) & Request.Form(str) & chr(34) & ","
next
a.Writeline(strtext)
'this will read the content fm a form and write into excel
%>
and the architecture is something like this:
-www(folder)
default.asp (file)
confirm.asp (file)
--file (folder)
And I am getting this error:
Permission denied
/sites/auto/confirm.asp, line 7
I do have it checked for the read/write permissions to accept anonymous write.
Thanks!
-Corey
ASKER
I also have my inputs if that will help now, so maybe I can create a reference?
<%
Dim Last_Namename,Last_Name,Fi rst_Namena me,First_N ame,Email_ Addressnam e,Email_Ad dress
Dim Home_Phonename,Home_Phone, Work_Phone name,Work_ Phone,Extn ame,Ext,Ce ll_Phonena me,Cell_Ph one
Dim Addressname,Address,Cityna me,City,St atename,St ate,ZipNam e,Zip
Dim Makename,Make,Modelname,Mo del,yearna me,year,mi leagename, mileage,pu rchase_yea rname,purc hase_year
Dim New_Usedname,New_Used,Purc hase_price name,Purch ase_price, Four_Wheel _Drivename ,Four_Whee l_Drive,Tu rboname,Tu rbo
Dim Engine_Typename,Engine_Typ e,Cylinder sname,Cyli nders,Best _Time_to_C ontact_You name,Best_ Time_to_Co ntact_You, Warrantyna me,Warrant y
Dim IPname,IP,User_Agentname,U ser_Agent
Dim strRefername,strRefer
Last_Namename = "Last Name: "
Last_Name = Request.Form("Last_Name")
First_Namename = "First Name: "
First_Name = Request.Form("First_Name")
Home_Phonename = "Home Phone: "
Home_Phone = Request.Form("Home_Phone")
Work_Phonename = "Work Phone: "
Work_Phone = Request.Form("Work_Phone")
Extname = "Extension: "
Ext = Request.Form("Ext")
Cell_Phonename = "Cell Phone: "
Cell_Phone = Request.Form("Cell_Phone")
Email_Addressname = "E-Mail Address: "
Email_Address = Request.Form("Email_Addres s")
Addressname = "Address: "
Address = Request.Form("Address")
Cityname = "City: "
City = Request.Form("City")
Statename = "State: "
State = Request.Form("State")
Zipname = "Zip: "
Zip = Request.Form("Zip")
Makename = "Make: "
Make = Request.Form("Make")
Modelname = "Model: "
Model = Request.Form("Model")
yearname = "Year: "
year = Request.Form("year")
mileagename = "Mileage: "
mileage = Request.Form("mileage")
purchase_yearname = "purchase_year: "
purchase_year = Request.Form("Purchase Year")
New_Usedname = "New or Used: "
New_Used = Request.Form("New_Used")
Purchase_pricename = "Purchase Price: "
Purchase_price = Request.Form("Purchase_pri ce")
Four_Wheel_Drivename = "Four Wheel Drive: "
Four_Wheel_Drive = Request.Form("Four_Wheel_D rive")
Turboname = "Turbo: "
Turbo = Request.Form("Turbo")
Engine_Typename = "Engine Type: "
Engine_Type = Request.Form("Engine_Type" )
Cylindersname = "Cylinders: "
Cylinders = Request.Form("Cylinders")
Best_Time_to_Contact_Youna me = "Best Time to Call: "
Best_Time_to_Contact_You = Request.Form("Best_Time_to _Contact_Y ou")
Warrantyname = "Warranty: "
Warranty = Request.Form("Warranty")
IPname = "IP Address: "
IP = Request.Form("IP")
User_Agentname = "Browser Info: "
User_Agent = Request.Form("User_Agent")
strRefername = "URL: "
strRefer = Request.Form("strRefer")
Set JMail = Server.CreateObject("JMail .Message")
JMail.MailServerUserName = "user@mydomain.com"
JMail.MailServerPassword = "password"
JMail.ISOEncodeHeaders = False
JMail.From = "contact@mydomain.com"
JMail.AddRecipient "contact@mydomain.com"
JMail.Subject = "Contact from mydomain"
JMail.Body = Last_Namename & Last_Name & vbcrlf&_
First_Namename & First_Name & vbcrlf&_
Home_Phonename & Home_Phone & vbcrlf&_
Work_Phonename & Work_Phone & vbcrlf&_
Extname & Ext & vbcrlf&_
Cell_Phonename & Cell_Phone & vbcrlf&_
Email_Addressname & Email_Address & vbcrlf&_
Addressname & Address & vbcrlf&_
Cityname & City & vbcrlf&_
Statename & State & vbcrlf&_
Zipname & Zip & vbcrlf&_
Makename & Make & vbcrlf&_
Modelname & Model & vbcrlf&_
yearname & year & vbcrlf&_
mileagename & mileage & vbcrlf&_
purchase_yearname & purchase_year & vbcrlf&_
New_Usedname & New_Used & vbcrlf&_
Purchase_pricename & Purchase_price & vbcrlf&_
Four_Wheel_Drivename & Four_Wheel_Drive & vbcrlf&_
Turboname & Turbo & vbcrlf&_
Engine_Typename & Engine_Type & vbcrlf&_
Cylindersname & Cylinders & vbcrlf&_
Best_Time_to_Contact_Youna me & Best_Time_to_Contact_You & vbcrlf&_
Warrantyname & Warranty & vbcrlf&_
vbcrlf&_
IPname & IP & vbcrlf&_
User_Agentname & User_Agent & vbcrlf&_
strRefername & strRefer
JMail.Priority = 1
JMail.Send("mail.mydomain. com")
%>
I take it tha dumping it to a CSV, you do not have to worry about mapping? But I want to make sure that if a field is added in the future (unlikely) that it would not mess anything up. The inputs (by themselves):
First_Name
Last_Name
Home_Phone
Work_Phone
Cell_Phone
Ext
Email_Address
Address
Apt
City
State
Zip
Make
Model
year
mileage
purchase_year
New_Used
Purchase_price
Four_Wheel_Drive
Turbo
Engine_Type
Cylinders
Best_Time_to_Contact_You
Warranty
Thanks!
-Corey
<%
Dim Last_Namename,Last_Name,Fi
Dim Home_Phonename,Home_Phone,
Dim Addressname,Address,Cityna
Dim Makename,Make,Modelname,Mo
Dim New_Usedname,New_Used,Purc
Dim Engine_Typename,Engine_Typ
Dim IPname,IP,User_Agentname,U
Dim strRefername,strRefer
Last_Namename = "Last Name: "
Last_Name = Request.Form("Last_Name")
First_Namename = "First Name: "
First_Name = Request.Form("First_Name")
Home_Phonename = "Home Phone: "
Home_Phone = Request.Form("Home_Phone")
Work_Phonename = "Work Phone: "
Work_Phone = Request.Form("Work_Phone")
Extname = "Extension: "
Ext = Request.Form("Ext")
Cell_Phonename = "Cell Phone: "
Cell_Phone = Request.Form("Cell_Phone")
Email_Addressname = "E-Mail Address: "
Email_Address = Request.Form("Email_Addres
Addressname = "Address: "
Address = Request.Form("Address")
Cityname = "City: "
City = Request.Form("City")
Statename = "State: "
State = Request.Form("State")
Zipname = "Zip: "
Zip = Request.Form("Zip")
Makename = "Make: "
Make = Request.Form("Make")
Modelname = "Model: "
Model = Request.Form("Model")
yearname = "Year: "
year = Request.Form("year")
mileagename = "Mileage: "
mileage = Request.Form("mileage")
purchase_yearname = "purchase_year: "
purchase_year = Request.Form("Purchase Year")
New_Usedname = "New or Used: "
New_Used = Request.Form("New_Used")
Purchase_pricename = "Purchase Price: "
Purchase_price = Request.Form("Purchase_pri
Four_Wheel_Drivename = "Four Wheel Drive: "
Four_Wheel_Drive = Request.Form("Four_Wheel_D
Turboname = "Turbo: "
Turbo = Request.Form("Turbo")
Engine_Typename = "Engine Type: "
Engine_Type = Request.Form("Engine_Type"
Cylindersname = "Cylinders: "
Cylinders = Request.Form("Cylinders")
Best_Time_to_Contact_Youna
Best_Time_to_Contact_You = Request.Form("Best_Time_to
Warrantyname = "Warranty: "
Warranty = Request.Form("Warranty")
IPname = "IP Address: "
IP = Request.Form("IP")
User_Agentname = "Browser Info: "
User_Agent = Request.Form("User_Agent")
strRefername = "URL: "
strRefer = Request.Form("strRefer")
Set JMail = Server.CreateObject("JMail
JMail.MailServerUserName = "user@mydomain.com"
JMail.MailServerPassword = "password"
JMail.ISOEncodeHeaders = False
JMail.From = "contact@mydomain.com"
JMail.AddRecipient "contact@mydomain.com"
JMail.Subject = "Contact from mydomain"
JMail.Body = Last_Namename & Last_Name & vbcrlf&_
First_Namename & First_Name & vbcrlf&_
Home_Phonename & Home_Phone & vbcrlf&_
Work_Phonename & Work_Phone & vbcrlf&_
Extname & Ext & vbcrlf&_
Cell_Phonename & Cell_Phone & vbcrlf&_
Email_Addressname & Email_Address & vbcrlf&_
Addressname & Address & vbcrlf&_
Cityname & City & vbcrlf&_
Statename & State & vbcrlf&_
Zipname & Zip & vbcrlf&_
Makename & Make & vbcrlf&_
Modelname & Model & vbcrlf&_
yearname & year & vbcrlf&_
mileagename & mileage & vbcrlf&_
purchase_yearname & purchase_year & vbcrlf&_
New_Usedname & New_Used & vbcrlf&_
Purchase_pricename & Purchase_price & vbcrlf&_
Four_Wheel_Drivename & Four_Wheel_Drive & vbcrlf&_
Turboname & Turbo & vbcrlf&_
Engine_Typename & Engine_Type & vbcrlf&_
Cylindersname & Cylinders & vbcrlf&_
Best_Time_to_Contact_Youna
Warrantyname & Warranty & vbcrlf&_
vbcrlf&_
IPname & IP & vbcrlf&_
User_Agentname & User_Agent & vbcrlf&_
strRefername & strRefer
JMail.Priority = 1
JMail.Send("mail.mydomain.
%>
I take it tha dumping it to a CSV, you do not have to worry about mapping? But I want to make sure that if a field is added in the future (unlikely) that it would not mess anything up. The inputs (by themselves):
First_Name
Last_Name
Home_Phone
Work_Phone
Cell_Phone
Ext
Email_Address
Address
Apt
City
State
Zip
Make
Model
year
mileage
purchase_year
New_Used
Purchase_price
Four_Wheel_Drive
Turbo
Engine_Type
Cylinders
Best_Time_to_Contact_You
Warranty
Thanks!
-Corey
ASKER
Well I did sorta figure part of it out, but I changed the code to
strFile="\file"
Set fs = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set a = fs.OpenTextFile(server.Map Path("\fil e") & strFile & ".csv", 8, true)
and I get:
Path not found
/sites/auto/confirm.asp, line 7
Getting closer I think.
Thanks!
-Corey
strFile="\file"
Set fs = Server.CreateObject("Scrip
Set a = fs.OpenTextFile(server.Map
and I get:
Path not found
/sites/auto/confirm.asp, line 7
Getting closer I think.
Thanks!
-Corey
ASKER
This seemed to work:
strFile="\file"
Set fs = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set a = fs.OpenTextFile(server.Map Path("file ") & strFile & ".csv", 8, true)
Now is there a way not to have the input names added each time? If not, that's cool.
Thanks!
-Corey
strFile="\file"
Set fs = Server.CreateObject("Scrip
Set a = fs.OpenTextFile(server.Map
Now is there a way not to have the input names added each time? If not, that's cool.
Thanks!
-Corey
>>Now is there a way not to have the input names added each time
Sorry don't quite understand you.
hongjun
Sorry don't quite understand you.
hongjun
ASKER
Well right now the text is:
Name EMail B1
Corey Bryant crb@merchantaccount4less.c om Submit
Name EMail B1
Corey Bryant crb@merchantaccount4less.c om Submit
Can it just be:
Corey Bryant crb@merchantaccount4less.c om Submit
Corey Bryant crb@merchantaccount4less.c om Submit
-Corey
Name EMail B1
Corey Bryant crb@merchantaccount4less.c
Name EMail B1
Corey Bryant crb@merchantaccount4less.c
Can it just be:
Corey Bryant crb@merchantaccount4less.c
Corey Bryant crb@merchantaccount4less.c
-Corey
It can be this only
Name EMail B1
Corey Bryant crb@merchantaccount4less.c om
Corey Bryant crb@merchantaccount4less.c om
Submit
hongjun
Name EMail B1
Corey Bryant crb@merchantaccount4less.c
Corey Bryant crb@merchantaccount4less.c
Submit
hongjun
ASKER
That's what I thought. But wanted to verify. Thanks!
-Corey
-Corey
With that you need a counter to do a vbcrlf.
Yes you can only have
Corey Bryant crb@merchantaccount4less.c om
Corey Bryant crb@merchantaccount4less.c om
Just delete the first part of the loop and only use the second part like this:
<%
dim strFile, strtext
dim a
strFile="\members"
Set fs = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set a = fs.OpenTextFile(server.Map Path(".\") & strFile & ".csv", 8, true)
'this create the file called members.csv
strtext =""
strtext = strtext & chr(34) & request("accountno") & chr(34) & ","
strtext = strtext & chr(34) & request("firstname") & chr(34) & ","
strtext = strtext & chr(34) & request("lastname") & chr(34) & ","
strtext = strtext & chr(34) & request("email") & chr(34) & ","
a.Writeline(strtext)
'this will read the content fm a form and write into excel
%>
<%
response.redirect "signup.asp"
%>
Corey Bryant crb@merchantaccount4less.c
Corey Bryant crb@merchantaccount4less.c
Just delete the first part of the loop and only use the second part like this:
<%
dim strFile, strtext
dim a
strFile="\members"
Set fs = Server.CreateObject("Scrip
Set a = fs.OpenTextFile(server.Map
'this create the file called members.csv
strtext =""
strtext = strtext & chr(34) & request("accountno") & chr(34) & ","
strtext = strtext & chr(34) & request("firstname") & chr(34) & ","
strtext = strtext & chr(34) & request("lastname") & chr(34) & ","
strtext = strtext & chr(34) & request("email") & chr(34) & ","
a.Writeline(strtext)
'this will read the content fm a form and write into excel
%>
<%
response.redirect "signup.asp"
%>
request("realname") and request("email") are the 2 form fields passed in.
<%
dim strFile, strtext
dim a
strFile="myfile"
Set fs = Server.CreateObject("Scrip
Set a = fs.OpenTextFile(server.Map
'this create the file called report.csv
strtext=""
strtext = strtext & chr(34) & "Name" & chr(34) & ","
strtext = strtext & chr(34) & "Email Address" & chr(34) & ","
a.WriteLine(strtext)
'this create two columns in excel file
strtext =""
strtext = strtext & chr(34) & request("realname") & chr(34) & ","
strtext = strtext & chr(34) & request("email") & chr(34) & ","
a.Writeline(strtext)
'this will read the content fm a form and write into excel
%>
hongjun