
This short tutorial is aimed at those people who would like to start learning a server language, such as Microsoft's ASP, and would like to know how to handle data passed from an HTML form.
This tutorial assumes you know the basics of ASP and programming, such as Variables and how to code a little in ASP.
A Form Processing script is usually a Server Scripted Page that process's information passed to it from an HTML Form.
Handling form data is a big part of web-sites these days. Without a some kind of form processor, html forms would have no use. Some uses of an form processing script are:
This page will show you how to create a simple html form, and an ASP form processing script that simply displays the values the user entered on the screen. Its not a major script, but it gives you an understanding of how you can access information passed from the clients browser to the server via a form.
The first thing you need to do is select what type of information your form will be collecting. This example will simple take in a persons named and age. So the first thing we do is to create the HTML form.
Start a new html document and type the following HTML code into the BODY of the document.
<form name="testform" action="process.asp">
<b>Your Name:</b><input type="text" name="username"><br>
<b>How Old are You?</b><input type="text" name="userage"</br>
<input type="Submit">
</form>
Save this document as 'testform.html'
Ok, now that we have created the form, we need to process the values with a separate ASP page, called 'process.asp'. In our passing form we had two fields, one for the users name called 'username' and one for their age called, 'userage'. We need to know the name of the elements we used in the form so that we can retrieve their data on the server page.
To create a server page, create a new file called 'process.asp' and enter the code below:
<%
'This line creates two variables to hold the passed information
dim name, age
'This line uses the ASP request object to get the users name.
name = request.form("username")
'This line gets the users age
age = request.form("userage")
'Now we have the values, we can display them:
document.write("Hello " & name & ",
you are " & age & " years old")
%>
Save this document as 'process.asp'
To test the script, we now need to upload both files to our ASP web Server. Upload them and then open the 'testform.html' from the web site you uploaded them to. Enter your name and age and press submit.
The form data is now passed off to the ASP page for processing, and the ASP page should display a welcome message containing your name an age.
Form processing is THAT simple.
Tutorial by Justin Kercher
2005.
This document may not be copied for use on another site.
Copyright© 2005.