Working with Forms in ASP
From JumbaWiki
Working with forms and ASP is one of the most common starting points for anyone new to the language. For this simple example, we are going to post a First and Last Name to a page, and print the resulting information. Firstly, it is important to understand when/how ASP pages are processed.
The page you are viewing now in your browser is what we will refer to as being at the 'client' end of the process. This is the end result of all interaction with the server, the most simple being the delivery of a straight .html page.
Active Server Pages allows another 'step' to occur when requesting a page. For instance as a user you click on a .asp link, rather than simply passing an address that is to be returned (eg.html page), an extra step of processing occurs where the page generated is the result of the processing of the ASP page.
This allows you to do retrieve data from request information, databases, external data through the XMLHTTPRequest object, and many other implementations. The result is a 'dynamic' page created for your user, that is customised to suit there requested information.
Now to some coding...on our starting HTML page where the user will enter their first name and last name we provide a HTML Form to allow data entry. The form will be something like this:
<form method=post action="shownames.asp" name="FrmNames" id="FrmNames"> First Name : <input type=text name=FrmFirstName id=FrmFirstName size=20> <br><Br> Last Name : <input type=text name=FrmLastName id=FrmLastName size=20> <input type=submit value="Post to ASP Page"> </form>
When the user enters in a first name and last name (typically you would add some javascript validation to this form to control what data is submitted), and hits the 'Post To ASP Page' button, all of form elements (input, select, textarea) will be 'posted' to the page that is defined in the 'action' tag of the FORM element.
Now to work with these posted objects. It is important to understand that any ASP page that you load has the Request Object available to it. What this means is you can retrieve information from information passed to this page in one of two formats.
In the case above, we are posting using the Request.Form Object. Alternatively, you could send this same information shown above via the 'querystring' of the URL by using an alternate (but less secure) method by navigating to the address shownames.asp?FrmFirstName=John&FrmLastName=Howard where the names entered are 'John' and 'Howard'.
The ASP page shown here will take the first name and last name and print them out on the resulting page.
<%@ Language=VBScript %>
<%
' create variables
Dim FirstName, LastName
' get the request objects
FirstName = Request.Form("FrmFirstName")
LastName = Request.Form("FrmLastName")
' convert them to uppercase to show manipulation
FirstName = UCase(FirstName)
LastName = UCase(LastName)
' show something on the page
response.write "Your name is " & FirstName & " " & LastName & ".<br>Thanks for stopping by!"
%>
Note that typically you would wrap proper HTML/Body tags around this page. This is a simple example only.

