Add structure to content with forms attached to twiki topics. TWiki forms (with form fields) and formatted search are the base for building database applications.
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 only form attached to it at a time.
Typical steps to build an application based on TWiki forms:
A Form Template specifies the fields in a form. A Form Template is simply a page containing a TWiki table, where each row of the table is one form field.
Input type | Type field | Size field | Value field |
---|---|---|---|
One or more checkboxes | checkbox | number of items per line | comma list of item labels |
One or more checkboxes, plus Set and Clear buttons | checkbox+buttons | (same) | (same) |
One or more radio buttons (radio buttons are mutually exclusive; only one can be selected) | radio | (same) | (same) |
Read-only label text | label | ignored | text |
Drop-down menu or scrollable box | select | 1 for drop down, 2 and up for scrollable box | comma-separated list of options |
A one-line text field | text | text box width in number of characters | initial text, if a new topic is created with a form template |
A text box | textarea | columns x rows, e.g. 80x6 ; default size is 40x5 | initial text, if a new topic is created with a form template |
YourForm
, ExpenseReportForm
, InfoCategoryForm
, RecordReviewForm
, whatever you need.
Name
, Type
, Size
, Values
, Tooltip message
, and Attributes
(see sample below).
Example: WebForm
| *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... | |
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...
You can also retrieve possible values for select, checkbox or radio types from other topics:
Example: WebForm
- In the WebForm topic, define the form:
Name Type Size Values Tooltip message Attributes TopicClassification select 1 blah blah... OperatingSystem checkbox 3 blah blah... OsVersion text 16 blah blah...
Leave the
Values
field blank.
- Then in the TopicClassification topic, define the possible values:
Name Type Tooltip message NoDisclosure option blah blah... Public Supported option blah blah... Public FAQ option blah blah...
Field values can also be obtained as the result of a FormattedSearch. For example,
%SEARCH{"Office$" scope="topic" web="%MAINWEB%" nototal="on" nosummary="on" nosearch="on" regex="on" format="$web.$topic" separator=", " }%
when used in the value field of the form definition, will take the set of field values to be all topic names in the Main web which end in "Office".
Notes:
label
, text
, and textarea
fields the value may also contain commas. checkbox
fields cannot be initialized through the form template.
label
field has no name (blank first column in the form definition) it will not be shown when the form is viewed, only when it is edited.
select
, checkbox
or radio
field, 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.
[[...]]
notation.
Tooltip message
column is used as a tooltip for the field name (only if field name is a WikiName) - you only see the tooltip in edit view.
Attributes
column is used to define special behavior for that form field (multiple attributes can be entered, with or without separators): H
indicates that this field should not be shown in view mode. However, the field is available for editing and storing information.
M
indicates 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 an oops
page. Mandatory fields are indicated by an asterisks next to the field name.
Forms have to be enabled for each individual web. The WEBFORMS
variable in WebPreferences is optional and defines a list of possible form templates.
Example:
- Set WEBFORMS = BugForm, FeatureForm, Books.BookLoanForm
WEBFORMS
enabled, 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 in WEBFORMS
, or the No form option.
WebTopicEditTemplate
topic in a web, or a new topic that serves as an application specific template topic. Initial Form values can be set there.
formtemplate
parameter in the (edit or save) URL. Initial values can then be provided in the URLs or as form values: name
, ex: ?BugPriority=1
namevalue=1
, ex: ?ColorRed=1
. <form name="newtopic" action="%SCRIPTURLPATH{"edit"}%/%WEB%/"> <input type="hidden" name="formtemplate" value="MyForm" /> New topic name <input type="text" name="topic" size="40" /> <input type="submit" value="Create" /> </form>
SubmitExpenseReport
topic where you can create new expense reports, a SubmitVacationRequest
topic, and so on. These can specify the required template topic with its associated form. Template topics has more.
FORMFIELD
, SEARCH
and METASEARCH
variables in TWikiVariables, and TWiki Formatted Search.
Example
TWiki users often want to have an overview of topics they contributed to. With the$formfield
parameter it is easy to display the value of a classification field next to the topic link:| *Topic* | *Classification* | %SEARCH{"%MAINWEB%.UserName" scope="text" regex="off" nosearch="on" nototal="on" order="modified" reverse="on" format="|<b>[[$web.$topic][$topic]]</b> |<nop>$formfield(TopicClassification) |" web="Sandbox"}%
checkbox
+multi
anywhere in the name
text
fields when a topic is saved. If you need linefeeds in a field, make sure it is a textarea
.
Very, very old TWiki releases used a system called the "TWikiCategoryTable". Later releases support automatic import of this data.
On upgrading from the previous TWiki, a Form Template topic has to be built for each web that used a Category Table, recreating the fields and values from the old twikicatitems.tmpl
. The replacement Form Template must be set as the first item in the WebPreferences variable WEBFORMS
. If missing, pages will display, but attempting to edit results in an error message.
The new Form Template system should work with old Category Table data with no special conversion. Data is assigned to Meta variables the first time an imported topic is edited and saved in the new system.
If things aren't working correctly, there may be useful entries in
data/warning.txt
.
Related Topics: UserDocumentationCategory, TWikiTemplates