Data Forms 
Data forms allow you to add structured data to topics. The data stored in the form fields can be used to search and filter topics. The combination of structured data and search queries are the base for building database applications.
 Overview 
By adding form-based input to freeform content, you can structure topics with unlimited, easily searchable categories. A form is enabled for a web and can be added to a topic. The form data is shown in tabular format when the topic is viewed, and can be changed in edit mode using edit fields, radio buttons, check boxes and list boxes. Many different form types can be defined in a web, though a topic can only have one form attached to it at a time.
Typical steps to build an application based on Foswiki forms: 
-  Define a form definition
-  Enable the form for a web
-  Build an HTML form to create new topics based on that template topic
-  Build a FormattedSearch to list topics that share the same form
For a step by step tutorial, see 
AnApplicationWithWikiForm.
 Defining a form 
A form definition specifies the fields in a form. A form definition is simply a page containing a Foswiki table, where each row of the table specifies one form field. 
-  Create a new topic with your form name: YourForm,ExpenseReportForm,InfoCategoryForm,RecordReviewForm, whatever you need.
-  Create a TML table, with each column representing one element of an entry field: Name,Type,Size,Values,Tooltip message, andAttributes(see sample below).
-  For each field, fill in a new line; for the type of field, select from the list.
-  Save the topic (you can later choose to enable/disable individual forms).
Example: 
 
| *Name* | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes* | 
 
| TopicClassification | select | 1 | NoDisclosure, PublicSupported, PublicFAQ | blah blah... |   | 
 
| OperatingSystem | checkbox | 3 | OsHPUX, OsLinux, OsSolaris, OsWin | blah blah... |   | 
 
| OsVersion | text | 16 | | blah blah... |   |
See 
structure of a form for full details of what types are available and what all the columns mean.
You can also retrieve possible values for 
select, 
checkbox or 
radio types from other topics:
Example:
 
-  In the WebForm topic, define the form:     
 
  Leave the Leave theValuesfield blank.
-  Then in the TopicClassification topic, define the possible values:     
 | *Name*            |
 | NoDisclosure      |
 | Public Supported  |
 | Public FAQ        |
      						| Name   |  			| NoDisclosure |  			| Public FAQ |  			| Public Supported |  
 
Field values can also be set using the result of expanding other macros. For example,
%SEARCH{"Office$" scope="topic" web="%USERSWEB%" nonoise="on" type="regex" format="$web.$topic" separator=", " }%
When used in the value field of the form definition, this will find all topic names in the Main web which end in "Office" and use them as the legal field values.
 Enabling forms by Web 
Forms have to be enabled for each individual web. The 
WEBFORMS setting in 
WebPreferences is optional and defines a list of possible form definitions.
Example: 
-  Set WEBFORMS = BugForm, FeatureForm, Books.BookLoanForm
 
-  With WEBFORMSenabled, an extra button is added to the edit view. If the topic doesn't have a Form, an Add Form button appears at the end of the topic. If a Form is present, a Change button appears in the top row of the Form. The buttons open a screen that enables selection of a form specified inWEBFORMS, or the No form option.
-  You have to list the available form topics explicitly. You cannot use a SEARCHto defineWEBFORMS.
 Adding a form to a topic 
 
-  Edit the topic and follow the "Add form" button to add a Form. This is typically done to a template topic, either to the WebTopicEditTemplatetopic in a web, or a new topic that serves as an application specific template topic. Initial Form values can be set there.
-   Note: Initial values will not be set in the form of a new topic if you only use the formtemplate parameter. Note: Initial values will not be set in the form of a new topic if you only use the formtemplate parameter.
 Changing a form 
 
-  You can change a form definition, and Foswiki will try to make sure you don't lose any data from the topics that use that form. 
-  If you change the form definition, the changes will not take affect in a topic that uses that form until you edit and save it.
-  If you add a new field to the form, then it will appear next time you edit a topic that uses the form.
-  If you delete a field from the form, or change a field name, then the data will not be visible when you edit the topic (the changed form definition will be used). If you save the topic, the old data will be lost (though thanks to revision control, you can always see it in older versions of the topic)
-  If two people edit the same topic containing a form at exactly the same time, and both change fields in the form, Foswiki will try to merge the changes so that no data is lost.
 Structure of a form definition 
A form definition specifies the fields in a form. A form definition is simply a TML table contained in a topic, where each row of the table specifies one form field.
Each 
column of the table is one element of an entry field: 
Name, 
Type, 
Size, 
Values, 
Tooltip message, and 
Attributes.
The 
Name, 
Type and 
Size columns are required. Other columns are optional. The form 
must have a header row (e.g. 
| *Name* | *Type* | *Size* |).
Name is the name of the form field.
The 
Type, 
Size and 
Value fields describe the legal values for this field, and how to display them. 
-  Typecheckboxspecifies one or more checkboxes. TheSizefield specifies how many checkboxes will be displayed on each line. TheValuefield should be a comma-separated list of item labels.
-  Typecheckbox+buttonswill add Set and Clear buttons to the basiccheckboxtype.
 
-  Typeradiois likecheckboxexcept that radio buttons are mutually exclusive; only one can be selected.
-  Typelabelspecifies read-only label text. TheValuefield should contain the text of the label.
-  Typeselectspecifies a select box. TheValuefield should contain a comma-separated list of options for the box. TheSizefield can specify a fixed size for the box (e.g.1, or a range e.g.3..10. If you specify a range, then the box will never be smaller than 3 items, never larger than 10, and will be 5 high if there are only 5 options.
-  There are two modifiers that can be applied to the selecttype:
 
-  Typetextspecifies a one-line text field.Sizespecifies the text box width in number of characters.Valueis the initial (default) content when a new topic is created with this form definition.
-  Typetextareaspecifies a multi-line text box. TheSizefield should specify columns x rows, e.g.80x6; default size is 40x5. As fortext, theValuefield specifies the initial text
-  Typedatespecifies a single-line text box and a button next to it; clicking on the button will bring up a calendar from which the user can select a date. The date can also be typed into the text box.Sizespecifies the text box width in characters. As fortext, theValuefield specifies the initial text
Tooltip message is a message that will be displayed when the cursor is hovered over the field in 
edit view.
Attributes specifies special attributes for the field. Multiple attributes can be entered, separated by spaces. 
-  An attribute Hindicates that this field should not be shown in view mode. However, the field is available for editing and storing information.
-  An attribute Mindicates that this field is mandatory. The topic cannot be saved unless a value is provided for this field. If the field is found empty during topic save, an error is raised and the user is redirected to anoopspage. Mandatory fields are indicated by an asterisks next to the field name.
For example, a simple form just supporting entry of a name and a date would look as follows:
| *Name* | *Type* | *Size* |
| Name   | text   | 80     |
| Date   | date   | 30     |
Field Name Notes: 
-  Field names have to be unique.
-  A very few field names are reserved. If you try to use one of these names, Foswiki will automatically append an underscore to the name when the form is used.
-  You can space out the title of the field, and it will still find the topic e.g. Aeroplane Manufacturersis equivalent toAeroplaneManufacturers.
-  If a labelfield has no name, it will not be shown when the form is viewed, only when it is edited.
-  Field names can in theory include any text, but you should stick to alphanumeric characters. If you want to use a non-wikiname for a select,checkboxorradiofield, and want to get the values from another topic, you can use[[...]]links. This notation can also be used when referencing another topic to obtain field values, but a name other than the topic name is required as the name of the field.
-  Leading and trailing spaces are not significant.
Field Value Notes:
-  The field value will be used to initialize a field when a form is created, unless specific values are given by the topic template or query parameters. The first item in the list for a select or radio type is the default item. For label,text, andtextareafields the value may also contain commas.checkboxfields cannot be initialized through the form definition.
-  Leading and trailing spaces are not significant.
-  Field values can also be generated through a FormattedSearch, which must yield a suitable table as the result.
-  Macros in the initial values of a form definition get expanded when the form definition is loaded. 
-  If you want to use a |character in the initial values field, you have to precede it with a backslash, thus:\|.
-  You can use <nop>to prevent macros from being expanded.
-  The FormatTokens can be used to prevent expansion of other characters.
 
General Notes:
-  The topic definition is not read when a topic is viewed.
-  Form definition topics can be protected in the usual manner, using  AccessControl, to limit who can change the form definition and/or individual value lists. Note that view access is required to be able to edit topics that use the form definition, though view access to the form definition is not required to view a topic where the form has been used.
 Values in other topics 
As described above, you can also retrieve possible values for select, checkbox or radio types from other topics. For example, if you have a rows defined like this:
| *Name*                 | *Type* | *Size* |
| AeroplaneManufacturers | select |        |
the Foswiki will look for the topic AeroplaneManufacturers to get the possible values for the 
select.
The AeroplaneManufacturers topic must contain a table, where each row of the table describes a possible value. The table only requires one column, 
Name. Other columns may be present, but are ignored.
For example:
| *Name* |
| Routan |
| Focke-Wulf |
| De Havilland |
Notes: 
-  The Valuescolumn must be empty in the referring form definition.
 Extending the range of form data types 
You can extend the range of data types accepted by forms by using 
Plugins. All such extended data types are single-valued (can only have one value) with the following exceptions: 
-  any type name starting with checkbox
-  any type name with +multianywhere in the name
 
Types with names like this can both take multiple values.
 Hints and tips 
 Build an HTML form to create new form-based topics 
 
-  New topics with a form are created by simple HTML forms asking for a topic name. For example, you can have a SubmitExpenseReporttopic where you can create new expense reports, aSubmitVacationRequesttopic, and so on. These can specify the required template topic with its associated form. Template topics has more.
 
A form definition specifies the fields in a form. A form definition is simply a page containing a Foswiki table, where each row of the table specifies one form field.
 Searching in form data 
The best way to search in form data is using the structured query language in the SEARCH macro. See 
QuerySearch for more information.
 Gotcha! 
 
-  Some browsers may strip linefeeds from textfields when a topic is saved. If you need linefeeds in a field, make sure it is atextarea.
Related Topics: UserDocumentationCategory, 
TemplateTopics, 
AnApplicationWithWikiForm