Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

January 06, 2000 10:14 AM

Active Server Pages Takes the Bite out of Forms

Windows IT Pro
InstantDoc ID #7951
Rating: (0)
Downloads
7951.zip

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

Related Content:

ARTICLE TOOLS

Comments
  • Bradley Young
    11 years ago
    May 29, 2001

    I, too, am very interested in this article as it describes exaclty what I require, but do not have the time (at the moment) to learn how to do it fully. However, upon running the page, despite copying exactly (at least I'm fairly sure), I get the following error:

    Microsoft VBScript compilation error '800a0400'

    Expected statement

    /bpyoung/addtext.asp, line 14

    option explicit

  • James Taylor
    12 years ago
    Jun 22, 2000

    This message is more for James R. Gregg. You might try the following to "clean up" your issue.
    1. Make sure you end up with three files (form.html, addtext.asp and feedback.txt)
    2. Place "Feedback.txt" into your C: directory, the other two into a directory in your wwwroot/inetpub folder. I placed mine in a folder named "CODE"
    3. Make sure you have properly "shared" that folder for ASP purposes.
    4. Access the files by typing http://localhost/CODE/form.html
    5. Enjoy playing with the app.
    I think your issue may have arisen out of not having your "ASP" file properly named. If you do it in notepad, you must make sure when you save your file that you select "all files" and not "text files" from the drop down box at th ebottom, otherwise your file could get saved like this 'addtext.asp.txt" which your computer will not process.

    Good Luck

  • Dan M
    12 years ago
    Jun 15, 2000

    The article incorrectly states: "ASP scripts work only on Web servers running IIS or machines running Peer Web Services (PWS) 3.0." This is not accurate. Chili!soft has a product called Chili!ASP that allows ASP scripts to run on several flavors of windows. htttp://www.chilisoft.com

  • Cliff Airhart
    12 years ago
    Apr 27, 2000

    Mark Minasi's Inside Out: "Active Server Pages Takes the Bite out of Forms" (February 2000) is a great article. What the article describes is exactly what I want to do. Will you send me the three files you reference in the article (form.html, addtext.asp, and feedback.txt)?
    --­Cliff Airhart

  • Mark Minasi
    12 years ago
    Apr 27, 2000

    Here's a quick way to get form.html and addtext.asp: Go to Windows 2000 Magazine's online archive (http://www
    .win2000mag.com/articles), scroll down and enter 7951 in the InstantDoc ID text box, and click Download the Code/Files in the Article Info box. Feedback.txt is just a blank file to start with, so you don't need to download it.
    --­Mark Minasi

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.