DOWNLOAD THE CODE:
Download the Code 7951.zip

 See correction 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")%>

   Prev. page   [1] 2     next page
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.



 
 

ADS BY GOOGLE