Structured data, how to set up and work with data forms.
Topic data is normally not visible when you view a topic (except for a small table at the bottom of the topic - dependent on the used skin). Topic data works "behind the scenes" and facilitates searches, reports and custom displays.
Topic data, or better: structured data, can be used in many ways. The Foswiki Support questions serves as a demonstration how topic data can be used:WEBFORMS
setting - see Enabling forms.
%FORMFIELD%
macro - see VarFORMFIELD
| *Name* | *Type* | *Size* | *Values* | *Description* | *Attributes* | *Default* | | TopicTitle | text | 100 | | Title of the topic | H | | | Version | select | 1 | Version in SVN,Foswiki 1.1.4,Foswiki 1.1.3,Foswiki 1.1.2,Foswiki 1.1.1 | | | | | Status | select | 1 | Asked,More info required,Answered | Mandatory status | M | Asked | | Related Topics | textboxlist | | | | | |In the next section we'll go into the details of the table contents.
The name of the data form topic usually ends with "Form". For example, the form topic for the Support Questions is named "QuestionForm". The form topic can be placed in any web, but usually this is in the same web as the topics that will be using it.
| *Name* | *Type* | *Size* | *Values* | *Description* | *Attributes* | *Default* |
Name | The name of the form field; must be unique for that form. |
Type | The data type: text, date, single or multi-value, labels (read-only). The type also defines how form field data can be entered in the edit screen, such as text field or radio buttons. |
Size | The input size of the form field inputs on the edit screen. |
Values | For checkboxes, radio buttons and dropdown lists: predefined input to select from. More advanced: this can be a dynamically generated list of values. |
Description | A message that describes the field. |
Attributes | Attributes controlling how the field is displayed. |
Default | if there is a default column, its value (or lack of value) is used as the default for new fields. This allows you to default the value of select , radio and checkbox to something other than the first values element |
undefined
(or any variant of that name, such as UnDefined), as that name is reserved for use in search queries.
Aeroplane Manufacturers
is equivalent to AeroplaneManufacturers
.
label
field has no name, it will not be shown when the form is viewed, only when it is edited.
select
, checkbox
or radio
field, can also be a topic-name used to fetch values from that topic.
[[...]]
double bracket links to link to a topic/field name that is not a wiki word.
[[topicname][field name]]
to use a field name other than the topic name. ie. [[ComputerManufacturers][Made by]]
ComputerManufacturers
is used to fetch values for the Madeby
field.)
Made by
becomes Madeby
.
Fühler
would be stored as Fhler
. The same field name on Foswiki 2.0 is stored as Fühler
. (See UpgradeGuide for more information.}
The control appearance is also specified by size and (initial) value. More on those attributes below.
Type | Description | Size attribute | Value attribute | Modifiers |
---|---|---|---|---|
checkbox |
One or more checkboxes. | How many checkboxes will be displayed on each line. | A comma-separated list of item labels. | checkbox+buttons will add Set and Clear buttons to the basic checkbox type. checkbox+values allows the definition of values that are different to the displayed text. |
date |
A single-line text box and a calendar icon 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. | The text box width in characters. | The initial text (unless default column exists). |
|
label |
Read-only label text. | The text of the label. | ||
radio |
Like checkbox except that radio buttons are mutually exclusive; only one can be selected. |
radio+values allows the definition of values that are different to the displayed text. |
||
select |
A select box / dropdown. | A fixed size for the box (e.g. 1 , or a range e.g. 3..10 . To get a dropdown, use size 1 . If you specify a range, the box will never be smaller than 3 items, never larger than 10, and will be 5 high if there are only 5 options. |
A comma-separated list of options for the box. | 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. You can combine these modifiers e.g. select+multi+values |
text |
A one-line text field. | The text box width in number of characters. | The initial (default) content when a new topic is created with this form definition (unless default column exists). |
|
textarea |
A multi-line text box. | Size in columns x rows, e.g. 80x6 ; default size is 40x5. |
The initial text (unless default column exists). |
| Field 9 | select+values | 1 | One, Two=2, Three=III, Four | Various values formats |displays as: The generated HTML code reveals that the form values differ from the option labels:
<select name="Field9" size="1" class="foswikiSelect"> <option value="One" class="foswikiOption">One</option> <option value="2" class="foswikiOption">Two</option> <option value="III" class="foswikiOption">Three</option> <option value="Four" class="foswikiOption">Four</option> </select>
color
:
| *Name* | *Type* | *Size* | | MyColor | color | 10 |
Example (click in the field to view):
checkbox
+multi
anywhere in the name
default
column exists), 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 definition.
|
character in the initial values field, you have to precede it with a backslash, thus: \|
. \|
escaping is _only active in the Values column. It is not usable elsewhere. Use &vbar;
or |
in other columns.
<nop>
to prevent macros from being expanded.
Values
column.
| *Name* | *Type* | *Size* | | AeroplaneManufacturers | select | |… Foswiki will look for the topic AeroplaneManufacturers to get the possible values for the
select
field.
The Values
column must be empty.
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 |
| *Name* | *Type* | *Size* | *Values* | | Subject | select+multi | 10 | ,%SEARCH{ \ "Wiki" \ scope="topic" \ web="%SYSTEMWEB%" \ nonoise="on" \ type="regex" \ format="$topic" \ separator=", " \ }% |Note the use of the backslash to be able to write the macro in a more readable way using multiple lines. The comma just before the
SEARCH
means "empty value" to make it possible to select none.
Sometimes you have a topic with a bullet list that can be used as selectable values. The rather advanced SEARCH
expression would be:
| Subject | select+multi | 10 | ,%SEARCH{ \ " *\s*.*?" \ topic="QuestionSubjectCategory" \ type="regex" \ multiple="on" \ casesensitive="on" \ nonoise="on" \ separator="," \ format="$pattern(.* \*\s*([^\n]*).*)" \ }% | | |You are not expected to write these kind of search expressions yourself, but if you like you can find more of these in Search Pattern Cookbook.
text
fields when a topic is saved. If you need linefeeds in a field, make sure it is a textarea
.
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, the user is presented with an error message. Mandatory fields are indicated by an asterisk next to the field name. |
| TopicTitle | text | 100 | | | H M |
WEBFORMS
setting. The setting accepts a comma-separated list of form topics:
* Set WEBFORMS = BugForm, FeatureForm, Books.BookLoanForm, %USERSWEB%.UserFormAs you can see, form topics located in other webs can be added by using their web prefix. You have to list the available form topics explicitly. You cannot use a
SEARCH
to define WEBFORMS
.
WEBFORMS
enabled, a form can be added or changed on the edit screen.
In the template initial field values can be set, like the "Status" field in this example.
WebTopicEditTemplate
topic to contain the form reference.
formtemplate
parameter to the edit (not save) URL.
Initial values can then be provided in the URLs or as form values.
For example:
%SCRIPTURL{edit}%/%WEB%/KnowledgeTopicAUTOINC00001?formtemplate=MyForm;Subject=FAQWhatIsWikiWiki;Category=One;Category=Two;action=form
XxxYyyAUTOINC00001
: creates a new auto-numbered topic name with base "XxxYyy" - see automatically generate unique topic names
formtemplate
: specifies the form topic, like: formtemplate=MyForm
name=value
, like: Subject=FAQWhatIsWikiWiki
name=value1;name=value2
, like: Category=One;Category=Two
action=form
: shows the topic data form and hides the topic text form
<form name="newtopic" action="%SCRIPTURLPATH{"save"}%/Sandbox/" method="post"> <input type="hidden" name="formtemplate" value="SimpleForm" /> <input type="hidden" name="topic" value="KnowledgeTopicAUTOINC00001" /> <input type="hidden" name="Subject" value="FAQWhatIsWikiWiki" /> <input type="hidden" name="Category" value="One" /> <input type="hidden" name="Category" value="Two" /> <input type="submit" class="foswikiSubmit" value="Create topic" /> </form>Creates: For an overview of web form parameters, see CGI and Command Line Scripts.
%SEARCH{ "QuestionForm.Status='Asked'" type="query" excludetopic="QuestionTemplate" web="%WEB%" format=" * [[$web.$topic][$formfield(TopicTitle)]] $formfield(Subject)" order="formfield(Extension)" nonoise="on" }%For a step by step tutorial, see the FAQ How can I create a simple data form based application?. See SEARCH for an overview of
SEARCH
parameters, and Query Search for the query language specifics.