The so-called complex form here refers to the form containing many different input types, such as drop-down list boxes, single-line text, multi-line text, numerical values, etc. In situations where such forms are often needed, there is a dynamic form generation program. This article introduces a system that saves form definition data in a database, uses ASP scripts to dynamically generate form HTML code, and scripts to verify form input.
1. Define the database table structure
You can often see forms like "weekly surveys" on the web, which is a form that needs to be updated frequently. If there is a program that dynamically generates forms and their verification scripts, it can greatly reduce the workload of making these forms.
In this article's dynamic form generation and verification example, we use an Access database to store the definition information about the form. At the same time, for a simple calculation, the data entered by the user in the form is also saved to the same database. Defining a form requires two tables: the first table (Definitons) is used to define the form input field, and the second table (Lists) holds additional information for each input field, such as selection items for the selection list.
The table Definitons contains the following fields:
FieldName - Assign the variable name to the input field of the form
Label - that is, text label, prompt text displayed in front of the input field
Type - a single character that represents the form input field and the type of input value
The details are as follows:
(t) Text input box, i.e. <INPUTTYPE="TEXT">.
(n) Text input box, but numerical value is required.
(m) Remarkable content, used for comments or other large amounts of text input, it is a multi-line text editing box.
(b) Require "Yes" or "No". In this implementation, check boxes will be used to obtain this input, and the text label of the check box is "Yes". If the user selects it, the return value is "on".
(r) Radio button.
(l) drop-down list box.
Min - Only valid for numeric input values, the minimum value is given here. In this example, there is a "Age" (age) digital input box, and its minimum value is set to 1.
Max—The value of this field is related to the input field form. For a digital input box, it represents the maximum allowed value. For example, the Max value of "Age" is 100. For text input boxes, Max represents the maximum number of characters allowed. For multi-line text editing boxes, Max represents the number of lines of text in the visible area.
Required - Indicates whether it is necessary to enter. If no input is entered, the input validator will report an error. In the form, the value that must be entered is marked with an asterisk and prompts the user to enter the value of the class as a footnote.
The example form in this article is an ASP programmer questionnaire. The definition of this form in the Definitons table is mainly as follows:
FieldNameLabelTypeMinMaxRequired
Name Name Text (t)-50 No
Age age number (n)1100 No
Sex Gender Radio Button (r)--Yes