Welcome, Registration, and other StartingPoints; TWiki history & Wiki style; All the docs...
View   r23  >  r22  ...
TWikiForms 23 - 15 Nov 2006 - Main.TWikiContributor
Line: 1 to 1
 

TWiki Forms

Line: 16 to 16
 
  1. Build an HTML form to create new topics based on that template topic
  2. Build a FormattedSearch to list topics that share the same form
Changed:
<
<

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

  • form template - a set of fields defining a form
    • A web can use one or more form templates
  • form - additional meta data (besides the freeform TEXTAREA) attached to a topic
    • Within a form-enabled web, individual topics can have a form or no form
  • form field - a named item in a form (also known as a key)
  • field type - selects the field type:
    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
  • field value - one or more values from a fixed set (select, checkbox, radio type) or free-form (label, text, text area).

Defining a Form

>
>

Defining a Form

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 specifies one form field.
 
  1. Create a new topic with your form name: YourForm, ExpenseReportForm, InfoCategoryForm, RecordReviewForm, whatever you need.
Changed:
<
<
  1. 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).
>
>
  1. Create a TWiki table, with each column representing one element of an entry field: Name, Type, Size, Values, Tooltip message, and Attributes (see sample below).
 
  1. For each field, fill in a new line; for the type of field, select from the list.
  2. Save the topic (you can later choose to enable/disable individual forms).
Changed:
<
<
Example: WebForm
>
>
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... |   |
Line: 58 to 36
 
OsVersion text 16   blah blah...  
Changed:
<
<
You can also retrieve possible values for select, checkbox or radio types from other topics:
>
>
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:

 
Changed:
<
<
Example: WebForm
>
>
Example:
 
  • In the WebForm topic, define the form:
Line: 74 to 54
 
  • Then in the TopicClassification topic, define the possible values:
Changed:
<
<
Name Type Tooltip message
NoDisclosure option blah blah...
Public Supported option blah blah...
Public FAQ option blah blah...
>
>
| *Name*            |
| NoDisclosure      |
| Public Supported  |
| Public FAQ        |
Name
NoDisclosure
Public Supported
Public FAQ
 

Field values can also be obtained as the result of a FormattedSearch. For example,

Changed:
<
<
%SEARCH{"Office$" scope="topic" web="%MAINWEB%" nototal="on" nosummary="on" nosearch="on" regex="on" format="$web.$topic" separator=", " }%
>
>
%SEARCH{"Office$" scope="topic" web="%MAINWEB%" nonoise="on" type="regex" format="$web.$topic" separator=", " }%
 
Changed:
<
<
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:

  • A very few field names are reserved. If you try to use one of these names, TWiki will automatically append an underscore to the name when the form is used.
  • 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, and textarea fields the value may also contain commas. checkbox fields cannot be initialized through the form template.
  • If a 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.
  • The topic definition is not read when a topic is viewed.
  • Field names can include any text, but you should stick to alphanumeric characters. If you want to use a non-wikiname for a 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.
  • Field names have to be unique. If the same name is necessary (as when the field values for several fields are obtained from the same topic), an alternative name must be assigned using the [[...]] notation.
  • The topic defining field values can also be generated through a FormattedSearch, which must yield a suitable table as the result.
  • Form definition topics can be protected in the usual manner, using TWikiAccessControl, to limit who can change the form template 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.
  • The 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.
  • The Attributes column is used to define special behavior for that form field (multiple attributes can be entered, with or without separators):
    • An attribute H indicates that this field should not be shown in view mode. However, the field is available for editing and storing information.
    • An attribute 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.
>
>
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 variable in WebPreferences is optional and defines a list of possible form templates.

Changed:
<
<
>
>
 Example:
  • Set WEBFORMS = BugForm, FeatureForm, Books.BookLoanForm
  • With 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.
Added:
>
>
  • You have to list the available form topics explicitly. You cannot use a SEARCH to define WEBFORMS.
 
Changed:
<
<

Add a form to a topic

>
>

Adding a form to a topic

 
Changed:
<
<
  • Edit a topic and follow the "Add form" button to add a Form to the topic. This is typically done to a template topic, either to the WebTopicEditTemplate topic in a web, or a new topic that serves as an application specific template topic. Initial Form values can be set there.
>
>
  • Edit the topic and follow the "Add form" button to add a Form. This is typically done to a template topic, either to the WebTopicEditTemplate topic in a web, or a new topic that serves as an application specific template topic. Initial Form values can be set there.
 
  • Additionally a new topic can be given a Form using the formtemplate parameter in the (edit or save) URL. Initial values can then be provided in the URLs or as form values:
    • other than checkboxes: name, ex: ?BugPriority=1
Line: 127 to 96
 
New topic name
Changed:
<
<
>
>
 

  • ALERT! Note: Initial values will not be submitted to the form of a new topic if you only use the formtemplate parameter.
Deleted:
<
<

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

Changing a form

  • You can change a form definition, and TWiki will try to make sure you don't lose any data from the topics that use that form.
Line: 147 to 112
 
  • 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)
Added:
>
>
  • If two people edit the same topic containing a form at exactly the same time, and both change fields in the form, TWiki will try to merge the changes so that no data is lost.

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

  • Type checkbox specifies one or more checkboxes. The Size field specifies how many checkboxes will be displayed on each line. The Value field should be a comma-separated list of item labels.
    • Type checkbox+buttons will add Set and Clear buttons to the basic checkbox type.
  • Type radio is like checkbox except that radio buttons are mutually exclusive; only one can be selected.
  • Type label specifies read-only label text, The Value field should contian the text of the label.
  • Type select specifies a select box. The Value field should contain a comma-separated list of options for the box. The Size field 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 select type:
      • select+multi turns multiselect on for the select, to allow Shift+Click and Ctrl+Click to select (or deselect) multiple items.
      • select+values allows the definition of values that are different to the displayed text. For example:
        | Field 9 | select+values | 5 | One, Two=2, Three=III, Four | Various values formats |
        shows but the values or options Two and Three are 2 and III respectively.
        You can combine these modifiers e.g. select+multi+values
  • Type text specifies a one-line text field. Size specifies the text box width in number of characters. Value is the initial (default) content when a new topic is created with this form template.
  • Type textarea specifies a multi-line text box. The Size field should specify columns x rows, e.g. 80x6; default size is 40x5. As for text, the Value field specifies the initial text
  • Type date specifies 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. Size specifies the text box width in characters. As for text, the Value field 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 H indicates that this field should not be shown in view mode. However, the field is available for editing and storing information.
  • An attribute 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.

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, TWiki 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 Manufacturers is equivalent to AeroplaneManufacturers.
  • If a label field 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, 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.
  • 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, and textarea fields the value may also contain commas. checkbox fields cannot be initialized through the form template.
  • 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.
  • Variables in the initial values of a form definition get expanded when form values are initialized from the form definition. The escape words $quot ("), $percnt (%), $dollar ($), $n (newline), and $nop can be used to prevent expansion.
General Notes:
  • The topic definition is not read when a topic is viewed.
  • Form definition topics can be protected in the usual manner, using TWikiAccessControl, to limit who can change the form template 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 TWiki 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 Values column 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 TWikiPlugins. 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 +multi anywhere 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 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.
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 specifies one form field.
 
Changed:
<
<

Searching for Form Data

>
>

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.

Line: 156 to 208
 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* |
Changed:
<
<
%SEARCH{"Main.UserName" scope="text" regex="off" nosearch="on" nototal="on" order="modified" reverse="on"
>
>
%SEARCH{"Main.UserName" scope="text" nosearch="on" nototal="on" order="modified" reverse="on"
 format="|$topic? |$formfield(TopicClassification? ) |" web="Sandbox"}%
Changed:
<
<

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:
  • any type name starting with checkbox
  • any type name with +multi anywhere in the name
Types with names like this can both take multiple values.

Gotcha!

>
>
Searching forms this way is obviously pretty inefficient, but it's easy to do. If you want better performance, take a look at some of the structured wiki extensions that support higher performance searching e.g. TWiki:Plugins.DBCachePlugin.

Gotcha!

 
  • Some browsers may strip linefeeds from text fields when a topic is saved. If you need linefeeds in a field, make sure it is a textarea.
Deleted:
<
<

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


Revision 23r23 - 15 Nov 2006 - 19:43:52 - TWikiContributor
Revision 22r22 - 04 Jun 2005 - 21:50:00 - TWikiContributor
This site is powered by the TWiki collaboration platform.
All material on this collaboration platform is the property of the contributing authors.
All material marked as authored by Eben Moglen is available under the license terms CC-BY-SA version 4.
Syndicate this site RSSATOM