| ~Wildfire: > Articles > Using Request.Form and Request.Querystring in ASP | |
| ~Look at: | Articles | FAQs | Resources | Reference | | |
Contents
IntroductionAt many points in the development of your web application you may want to use HTML forms through a script to calculate and output a custom page on the results. Before ASP you generally had to rely on pre-built CGI scripts etc. You can build Active Server Pages to handle input from forms, calculate on the values entered and output a custom result. The Two MethodsThere are two main methods of transferring data as you may know from previous HTML experience. These are "POST" and "GET". Simply a HTML post will send the results of the form to the script, whereas a "GET" will append the form results onto the end of the URL/Address for the page. Request.Form & POSTingIt is easy to access the contents of a form in ASP, below I have written (the important parts) of the two pages needed, first the HTML page that sends the form details, then the ASP script that gets the results and simply writes them to the browser: The HTML Page <BODY> Now the Active Server Script to receive the results and simply return them to the browser: <% This as you can see is just a fairly simple script, but it shows you how to get the values from the form and enter it into the "application" on the page. Request.Querystring & GETtingThe request.querystring method is very similar to the request.form method. Firstly you should take a look at a sample URL, it may be useful to see what is happening when you submit a GET request:
http://www.company.com/mypage.asp?name=jamie%20mchale&email=wildfire@btinternet.com
This is a simple URL with a few fields that might be generated from an HTML form. Note that each field is separated by an ampersand: "&". Also any special characters are converted into a coded URL format, for example all spaces are converted to: "%20". Now the code for receiving the values:
<% myVar = request.querystring("nameOfField") %>
This as you can see is very much like the request.form method. ApplicationsThe methods that you learnt to use above are useful in all aspects of your ASP development. You can use them to post form data to a page that updates a database, redirect a user to a new page based on their preferences, or build up cumulatively the results of a form. For example you may have a long form for the user to fill in. You can break this down into several stages by asking a few questions then transferring the values to the next page and then write them in as hidden fields in the HTML form.
|
|||
| Top of Page | |
| ~Look at: | Articles | FAQs | Resources | Reference | | |
| © Jamie McHale 1998 - 2000 - http://www.btinternet.com/~wildfire/ |