Save Inputted Data From a Form as a CSV File

Question:
How do I get all the inputted information from an HTML form and save it to my server as a CSV (comma-separated values) file which updates itself?

Answer:

If you are using Active Server Pages (ASP), this is very easy. The secret to working that magic is in the FileSystemObject. I have included a sample page that you can use as a springboard into your project. Notice that in the sample code, I have included an HTML

. The form, comprising of three HTML boxes and a single Submit button, includes an ASP page as the value of its ACTION property. That ASP page will execute when the user clicks the Submit button. When that ASP page runs, you can extract the values the user entered into the textboxes using this code:

TextFromFirstTextbox = Request.Form("text1")

After you have the values temporarily stored in variables, you can write the values out to your CSV file. The first thing to do is create the FileSystemObject:

Set fs = CreateObject("Scripting.FileSystemObject")

Next, create a text file and hold the reference to that file. The first parameter identifies the path and filename. The second parameter tells the FileSystemObject if it should overwrite the file when an older copy of file exists. I have set the second parameter to “True”, which indicates that it should overwrite the file:

	Set a = fs.CreateTextFile(PathAndFileName, True)	

Write the file to disk:

	a.Write(WriteThis)	

Finally, close the file:

	a.Close

That’s all there is to it. To see it in action, try this sample code in any browser against a Microsoft IIS 4.0 Web Server.

<%@ Language=VBScript %><%TextFromFirstTextbox = Request.Form("text1")TextFromSecondTextbox = Request.Form("text2")TextFromThirdTextbox = Request.Form("text3")If	Len(TextFromFirstTextbox) > 0 and _	Len(TextFromSecondTextbox) > 0 and _	Len(TextFromThirdTextbox) > 0 _Then		'WRITE TO CSV	Dim WriteThis	Dim PathAndFileName 		WriteThis = TextFromFirstTextbox & "," & TextFromSecondTextbox & "," & TextFromThirdTextbox	PathAndFileName = "C:MyData.csv"		Set fs = CreateObject("Scripting.FileSystemObject")	Set a = fs.CreateTextFile(PathAndFileName, True)		a.Write(WriteThis)		a.Close		Dim MessageOut	MessageOut =  "The form data (" & WriteThis & ") has been written to " & PathAndFileName & ""	End If%>

Writing Form Input to a CSV File

<%=MessageOut%>

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a