The Caboteria / TWiki Web / TWikiForms (revision 22)

TWiki Forms

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.

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 only form attached to it at a time.

Typical steps to build an application based on TWiki forms:

  1. Define a form template
  2. Enable the form for a web
  3. Add the form to a template topic
  4. Build an HTML form to create new topics based on that template topic
  5. Build a FormattedSearch to list topics that share the same form

Defining a Form Template

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.

Form Template Elements

Defining a Form

  1. Create a new topic with your form name: YourForm, ExpenseReportForm, InfoCategoryForm, RecordReviewForm, whatever you need.
  2. Create a TWiki table, with each column head representing one element of an entry field: Name, Type, Size, Values, Tooltip message, and Attributes (see sample below).
  3. For each field, fill in a new line; for the type of field, select from the list.
  4. Save the topic (you can later choose to enable/disable individual forms).

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...  

    ALERT! 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:

Enabling Forms by Web

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

Add a form to a topic

Build an HTML form to create new Form-based topics

Changing a form

Searching for Form Data

TWiki Forms accept user-input data, stored as TWikiMetaData. Meta data also contains program-generated info about changes, attachments, etc. To find, format and display form and other meta data, see TWikiMetaData, 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"}%

Extending the range of form data types

Several Plugins allow you to extend the range of data types accepted by forms. For example, the TWiki:Plugins.DateFieldPlugin lets you add a 'date' type to the available data types. All data types are single-valued (can only have one value) with the following exceptions: Types with names like this can both take multiple values.

Gotcha!

Importing Category Table Data

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.

TIP If things aren't working correctly, there may be useful entries in data/warning.txt.

Related Topics: UserDocumentationCategory, TWikiTemplates

Edit | Attach | Print version | History: r28 | r24 < r23 < r22 < r21 | Backlinks | Raw View | Raw edit | More topic actions...
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding The Caboteria? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.TWikiForms.