Not Serializable
The FormCollection allows developers easy access to the name-value pairs contained in the body of an HTTP POST request.
FormCollection provides a number of utilities to help developers quickly access the names and corresponding values in the post content from a form. The body of the request must be structured in conformance with the form content type of application/x-www-form-urlencoded. In general, a form in a web page or most web libraries will follow this convention. More detailed information can be found in the HTML 4.01 specification.
To initialize a FormCollection variable with the post content from an incoming GotRequest event, set the InitializeWith property of a variable in the event handler to the event parameter Body.
To read a form field in from the FormCollection type, use the .NET indexer syntax on the variable, specifying the name of the form field as the argument to the indexer. For example, if one had a variable of the name post, and wanted to know the value of a form field called 'user', then the C# snippet post["user"] would resolve to that value. Note that one can use the GetValues( System.String ) method to return a string array, which is the more appropriate option if your form defines the same field name more than once.
To programmatically determine all the form fields passed in, three members defined by FormCollection in particular are of interest. One is the Count property, which will indicate how many fields are defined in total. Using that as a loop count, one can then use the GetNameAt( System.Int32 ) method and this[ System.Int32 ] indexer to determine the name and value(s) of each form field defined in the request. For example, one can build a CustomCode action that takes a variable named post as an argument, and iterates over every form field like the below example:
Example 34.1. Dynamically Determining Contents of the FormCollection
public static string Execute(Metreos.Types.Http.FormCollection post)
{
for(int i = 0; i < post.Count; i++)
{
string post = post.GetNameAt(i);
string post = post[i]; // note that one may want to not use the indexer and instead
// use post.GetValuesAt(i) if the field has multiple string values
//perform logic...
}
return String.Empty;
}
None.
| .NET Type | Description |
|---|---|
String | Accepts a string that follows the form content type of application/x-www-form-urlencoded. In common practice this value comes from the Body event parameter of the GotRequest event. |
| Method Name | Description |
|---|---|
| GetNameAt | Retrieves the name of the form field at the given index. |
| GetValues | Specify the name of a field form of interest. The resulting string array is a list of all values for the named field. If no occurrences of the form field exist, then a null is returned. |
| GetValues | Specify the index of a field form of interest. The resulting string array is a list of all values for the field at the specified index. If no occurrences of the form field exist, then a null is returned. If an index is specified that falls ouf of the valid positions in the FormCollection variable, then an unhandled exception will occur and the script instance will halt. |
| Reset | Clears the variable to an uninitialized state. |
| GetEnumerator | This method should not be used. Instead use Count in conjunction with a for loop structure. |
| Property Name | .NET Type | Description |
|---|---|---|
| Count | System.Int32 | Returns the number of form fields defined. Note that multiple form fields with the same name all count as only one field. |
| .NET Indexer Type | .NET Return Type | Description |
|---|---|---|
System.String | System.String | Specify the name of a field form of interest. The resulting string array is a list of all values for the named field. If no occurrences of the form field exist, then a null is returned. |
System.Int32 | System.String | Specify the index of a field form of interest. The resulting string is the value of the form field found at the specified index. If no occurrences of the form field exist, then a null is returned. If an index is specified that falls ouf of the valid positions in the FormCollection variable, then an unhandled exception will occur and the script instance will halt. |