F.2.4- Harvesting Data for Use in the Response Page
Created
by Brendan Doss.
|
| << F.2.3- General Information on Data Returned from Forms | AppendixF | F.2.5- Common Errors in the Use of Forms >> |
Harvesting Data for Use in the Response Page
When the server receives the URL+data (from GET method) or the URL and separate data (from the POST method), ASP grabs the data, parses it, and stores it in a collection of the Request object. In the case of POST, it goes into the Forms collection, and in the case of GET, into the QueryString collection. You can extract the information one of two ways:
- Parse the information out of the entire string by hand
- Read the data as members of a Request object collection
In most cases you'll do the latter, but we'll also demonstrate the former for use with text areas.
As we've seen, data is returned from the GET method in several parts. The first is the URL for the response page itself, which is no different to a URL sent by a non-form hyperlink. Next is the question mark that separates the URL from the Data. The data then appears in a pattern of name=value pairs, separated by an ampersand (&). The name will be the string given in the NAME value of the INPUT tag (see details specific to each type below). The value will be what the user typed or selected in the field.
Although this sounds like a lot of characters to remember, keep in mind that you will rarely have to deal with them directly, since ASP takes care of parsing the information into its Request collections. Furthermore, once you use the RequestSniffer (below) on a few forms, you will have a good feel for what these strings look like.
The use of characters such as the ampersand and question mark create the problem of how to handle those characters if they are part of the data. HTTP converts most non-alphanumeric characters into code (their decimal equivalents delimited by a % character: this is known as character escaping). The most common codes are introduced in the section below on text area fields. The most important exception is a space, which is converted to the plus sign.
Data is returned from the POST method differently, since it is hidden in a separate data stream. The URL will appear the same as that from a non-form hyperlink, and there are no issues of data separation because the data goes directly into the ASP Request.Form collection.
The syntax to read information from a collection is not difficult:
varMyVariable = Request.Querystring("NameOfFormElement")
We discussed this in depth in the chapter on the Request object. For this appendix, we want to move right on to handling the scores of permutations of data from forms.
| << F.2.3- General Information on Data Returned from Forms | AppendixF | F.2.5- Common Errors in the Use of Forms >> |

RSS
