Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


February 2000

Active Server Pages Takes the Bite out of Forms


RSS
Subscribe to Windows IT Pro | See More Active Server Pages (ASP) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

 See corrections to this article

I occasionally have to build a Web site, an experience that is always humbling. My problem is that I don't do Web work often enough to build any real expertise, and the time between my Web adventures is usually long enough that I forget everything I learned on the previous project. Fortunately, HTML tags simplify Web work. And even if you forget the tags, you can use Microsoft Word or Microsoft FrontPage to handle them. But gathering information from forms for use on a Web page is a hassle.

I don't want to learn Perl or any other Common Gateway Interface (CGI) programming tool to handle forms. I maxed out at 20 programming and macro languages, and I refuse to learn any more. I usually let FrontPage's built-in form bot handle the forms. Although FrontPage is a good program, getting FrontPage's Internet Information Server (IIS) extensions to work is difficult. Even FrontPage 2000's form bot is rather fragile. Downloading and installing the FrontPage 2000 IIS extensions is a challenge. As I performed this task, I worried about disaster recovery—did I want to add a step to rebuilding my Web server? I wanted to avoid using the extensions, so I searched for a way to easily collect and store form information without using heavy-duty programming. Then I remembered Active Server Pages. ASP lets you use VBScript to build server-side Web-based applications. VBScript, a variant of Visual Basic (VB), is ideal for occasional programmers.

The Task
I needed to collect comments and stories about software bugs that readers had submitted to my Software Conspiracy Web site (http://www.softwareconspiracy.com). I wanted the ASP script to collect three identification fields (name, telephone number, and email address) and a comment field, surround each field with double quotes, put commas between the fields for ease of importing to programs such as Microsoft Excel or Microsoft Access, and append the new information to an ASCII file called feedback.txt.

I feared that the project might be time-consuming, but it took only about an hour and a half. For illustrative purposes, I've summarized only the program's essentials. To save space, my example doesn't include error-handling code. You might find this example useful on your next Web project that involves forms.

In the example, I display a simple form that asks for a user's name and email address. When the user submits this information, ASP shows the information to the user and stores it in feedback.txt.

In my project, I used three files: the HTML file with the form (form.html), the ASP file to collect the data and write it out (addtext.asp), and the file to write the data to (feedback.txt). The HTML file looked like the following file:

<form method="POST" action="addtext.asp"><BR>
<p>Name<input type="text" size="35" maxlength="256" name="Username"></p><BR>
<p>Email<input type="text" size="35" maxlength="256" name="UserEmail"></p><BR>
<p><input type="submit" value="Submit Info"> <input type="reset" value="Clear Form"></p><BR>
</form>

The HTML

tag takes two parameters: method="POST" and action="addtext.asp". The first parameter is standard, but the second parameter is unique. The second parameter is the part of the statement that tells the user's Web browser to ask the Web server to start the addtext.asp program. If this program isn't in the same directory as the form, you need to provide the full pathname. The

(i.e., paragraph) and tags simply display descriptive text (e.g., name) on the screen and put fields on the browser so that users can enter their responses. The last two tags tell the browser to put a Submit Info button and a Clear button on the screen. You don't need to do any programming to make these functions work; they're built into the HTML commands.

In my example, the ASP file looked like the following file:


<%@ Language=VBScript %><BR>
<%<BR>
option explicit<BR>
dim fso, myfile, uname, email<BR>
set fso = CreateObject _<BR>
("Scripting.FileSystemObject")<BR>
set myfile = fso.OpenTextFile _<BR>
("c:\feedback.txt",8,0)<BR>
uname = request.form("Username")<BR>
email = request.form("UserEmail")<BR>
myfile.writeline(uname & " " & email)<BR>
myfile.close<BR>
set myfile = nothing<BR>
%><BR>
<p>Name=<%=request.form("username")%><BR>
<p>Email address=<%=request.form("useremail")%>

   Previous  [1]  2  Next 


Corrections to this Article:

  • Inside Out: “Active Server Pages Takes the Bite out of Forms” (February 2000) contains an Active Server Pages (ASP) file in which some lines of code wrap across two lines of text but don’t contain a continuation character sequence ( _). A correct version of the file is available for download at http://www.win2000mag.com/articles. Enter 7951 in the InstantDoc ID text box and click on the Zip file in the Article Info box.

Top Viewed ArticlesView all articles
Anti-Virus Vendors Prepare for War with Microsoft ... Again

When Microsoft announced its Windows Live OneCare security and PC health product over five years (as MSN OneCare), Symantec, McAfee, and the other consumer-oriented security vendors reacted with stunning vigor. ...

What You Need to Know About Microsoft's x64 Server Product Plans

What do Longhorn Server, Windows Compute Cluster Server, and Windows Vista have in common? The x64 platform. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...


Task Automation Whitepapers Business Innovation with Data Center Transformation

Batch Job Scheduling and .NET in 2008

Continuous Data Protection and Recovery for Microsoft Exchange

Related Events WinConnections and Microsoft® Exchange Connections

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Test Drive IT Solutions and Get Free Music Downloads
Solve your toughest IT problems with these free downloads and receive 5 free music downloads!


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home asp.netPRO Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement | Reprints and Licensing