Form Collection (Dundas Upload Control 2.0)

Dundas

Form Collection (Dundas Upload Control 2.0)

Overview | Properties | Methods

Consists of FormItem objects which store uploaded form data.

Remarks

To use the Upload control the html form which POSTS the data must have an ENCTYPE of "Multipart/Form-Data".

The Form collection is used to retrieve form data. You MUST use this collection when examining form elements and their values since a form with an ENCTYPE of "Multipart/Form-Data" POSTS the data in such a way that you can no longer use ASP's Request.Form object to retrieve the data.

This collection is zero-based.

If a form element was not populated by the user then there will be no corresponding FormItem object in the control's Form collection (e.g. if you loop through the Form collection with a For ... Each loop there will be no FormItem object for the form elements left empty by the user). If you retrieve the value of a particular form element which was left empty by the user the return will be "Empty". You can test to see if the user left a form element blank, or empty, by using VBScript's IsEmpty method.

To use the Form collection you MUST CALL one of the following methods: the Save method of either the Upload control or a NextFile object; or the SaveToMemory method of either the Upload control or a NextFile object. Please note that using the GetNextFile method (which returns a NextFile object) will populate the Form collection with all form data up to the file input box in question. The Upload object's save methods, however, populates the Form collection with ALL POSTED form data in one method call.

To retrieve form items you can specify the name of the form element via its string key (e.g. strVariable = objUpload.Form("txtSomeTextBox"). Alternatively you can retrieve an element's value by specifying the appropriate numerical index (e.g. strVariable = objupload.Form(0)).

You can retrieve multiple selections for one form element (e.g. a listbox) by using the Count property of the FormItem object (this will have the total number of items selected for the form element) along with the Value method. Use a For loop with the Count property of the FormItem object as the upper loop delimiter and call the Value method for each item. For example, to retrieve all selected elements for a multi-item listbox (named "ListBox") you could use the following syntax:

For i = 0 To objUpload.Form("ListBox").Count - 1

Response.Write objUpload.Form("ListBox").Value(i)

Next
Note: alternatively you can also use a For ... Each loop to access multiple-item form element values.

To iterate through all form elements you can use a standard For loop with the upper delimiter set to one less than the Form collection's Count property. You can also loop through all form elements by using a For Each loop (e.g. For Each Item in objUpload.Form). Then access each form element using the following syntax: strSomeString = objUpload.Form(Item).

The Form collection supports the following properties and methods:

Properties

Description

Count

Read-only property which stores the number of FormItem objects in the collection.
 

Methods

Description

Item

Use this method to retrieve items from the collection. The default member of the collection.
 

The Item method is the default member of the collection so it does not have to be used explicitly. For example, "Set objFormItem = objUpload.Form(0).Item" accomplishes the same thing as "Set objFormItem = objUpload.Form(0)".

See Also: FormItem Object | How to Use the Dundas Upload Control | Tutorial 1: Uploading Multiple Files and Using the Form and Files Collections