none
[openafs-wiki.git] / TWiki / TWikiForms.mdwn
1 <div>
2   <ul>
3     <li><a href="#TWiki Forms"> TWiki Forms</a><ul>
4         <li><a href="#Overview"> Overview</a></li>
5         <li><a href="#Defining a Form Template"> Defining a Form Template</a><ul>
6             <li><a href="#Form Template Elements"> Form Template Elements</a></li>
7             <li><a href="#Defining a Form in One Topic"> Defining a Form in One Topic</a></li>
8             <li><a href="#Defining a Form with Multiple To"> Defining a Form with Multiple Topics</a></li>
9           </ul>
10         </li>
11         <li><a href="#Enabling Forms by Web"> Enabling Forms by Web</a></li>
12         <li><a href="#Including Forms in New Topics"> Including Forms in New Topics</a></li>
13         <li><a href="#Setting Up Multiple Form Options"> Setting Up Multiple Form Options</a></li>
14         <li><a href="#Form Data Storage"> Form Data Storage</a></li>
15         <li><a href="#Using Form Data"> Using Form Data</a></li>
16         <li><a href="#Main Changes from Category Table"> Main Changes from Category Tables</a><ul>
17             <li><a href="#Importing Category Table Data"> Importing Category Table Data</a></li>
18           </ul>
19         </li>
20       </ul>
21     </li>
22   </ul>
23 </div>
24
25 # <a name="TWiki Forms"></a> TWiki Forms
26
27 _Form-based input in topics, with name/value pairs stored as Meta Data variables; choose one of multiple forms per web &amp; topic_
28
29 ## <a name="Overview"></a> Overview
30
31 By adding form-based input to freeform content, you can structure topics with unlimited, easily searchable categories. When forms are enabled for a web and selected in a topic, a single form appears in edit mode, and the contents are rendered as a table when viewed on the display page. You can define unlimited forms per web. For each topic, you can select a template if more than one is defined, or remove forms entirely. Form input values are stored as [[TWikiMetaData]]; all data is saved.
32
33 Form Templates replace TWikiCategoryTables from the 01-Dec-2000 version of TWiki. - see [[#FormsVsCategoryTables|Main/WebHome#FormsVsCategoryTables]]
34
35 ## <a name="Defining a Form Template"></a> Defining a Form Template
36
37 A Form Template is simply a page containing your form, defined as a table where each row is one form field.
38
39 ### <a name="Form Template Elements"></a> Form Template Elements
40
41 - **form template** - a set of fields defining a form (replaces _category table definition_)
42   - A web can use one or more form templates
43 - **form** - a topic containing additional meta data (besides the freeform TEXTAREA) that categorizes the content (replaces _category table_)
44   - Within a form-enabled web, individual topics can have a form or no form
45 - **form field** - a named item in a form (replaces _category item name_)
46 - **field type** - selects the INPUT type: <table border="1" cellpadding="0" cellspacing="0">
47   <tr>
48     <th bgcolor="#99CCCC"><strong> Input type </strong></th>
49     <th bgcolor="#99CCCC"><strong> Type field </strong></th>
50     <th bgcolor="#99CCCC"><strong> Size field </strong></th>
51     <th bgcolor="#99CCCC"><strong> Value field </strong></th>
52   </tr>
53   <tr>
54     <td> One or more checkboxes </td>
55     <td><code>checkbox</code></td>
56     <td> number of checkboxes per line </td>
57     <td> comma list of checkbox labels </td>
58   </tr>
59   <tr>
60     <td> One or more checkboxes, plus <strong>Set</strong> and <strong>Clear</strong> buttons </td>
61     <td><code>checkbox+buttons</code></td>
62     <td> (same) </td>
63     <td> (same) </td>
64   </tr>
65   <tr>
66     <td> Read-only label text </td>
67     <td><code>label</code></td>
68     <td><code>1</code></td>
69     <td> (unused) </td>
70   </tr>
71   <tr>
72     <td> One or more radio buttons </td>
73     <td><code>radio</code></td>
74     <td> number of radio buttons per line </td>
75     <td> comma list of checkbox labels </td>
76   </tr>
77   <tr>
78     <td> Drop-down menu or scrollable box </td>
79     <td><code>label</code></td>
80     <td><code>1</code> for drop down, <code>2</code> and up for scrollable box </td>
81     <td> comma list of options </td>
82   </tr>
83   <tr>
84     <td> A one-line text field </td>
85     <td><code>text</code></td>
86     <td> text box width in number of characters </td>
87     <td> (unused) </td>
88   </tr>
89   <tr>
90     <td> A text box; size is 40x10 (columns x rows) </td>
91     <td><code>textarea</code></td>
92     <td> columns x rows, e.g. <code>40x6</code></td>
93     <td> (unused) </td>
94   </tr>
95 </table>
96 - **field value** - one or more values from a fixed set (select, checkbox, radio type) or free-form (text). (replaces _category item value_)
97
98 ### <a name="Defining a Form in One Topic"></a> Defining a Form in One Topic
99
100 1. Create a new topic with your form name: <code>**YourForm**</code>, <code>**ExpenseReport**</code>, <code>**InfoCategory**</code>, <code>**RecordReview**</code>, whatever you need.
101 2. Create a TWiki table, with each column head representing one element of an entry field: <code>**Name**</code>, <code>**Type**</code>, <code>**Size**</code>, <code>**Values**</code>, and <code>**Tooltip message**</code> _(see sample below)_.
102 3. For each field, fill in a new line; for the type of field, select from the list.
103 4. Save the topic _(you can later choose to [[enable/disable|Main/WebHome#EnablingForms]] individual forms)_.
104
105 > **Example:**
106 >
107 > <code>**WebForm**</code>
108 >
109 >     | *Name* | *Type* | *Size* | *Values* | *Tooltip message* |
110 >     | Know.TopicClassification | select | 1 | Know.NoDisclosure,
111 >       Know.PublicSupported, Know.PublicFAQ | blah blah... |
112 >     | Know.OperatingSystem | checkbox | 3 | Know.OsHPUX, Know.OsLinux,
113 >       Know.OsSolaris, Know.OsWin | blah blah... |
114 >     | Know.OsVersion | text | 16 | | blah blah... |
115 >
116 > <table border="1" cellpadding="0" cellspacing="0">
117 >   <tr>
118 >     <th bgcolor="#99CCCC"><strong> Name </strong></th>
119 >     <th bgcolor="#99CCCC"><strong> Type </strong></th>
120 >     <th bgcolor="#99CCCC"><strong> Size </strong></th>
121 >     <th bgcolor="#99CCCC"><strong> Values </strong></th>
122 >     <th bgcolor="#99CCCC"><strong> Tooltip message </strong></th>
123 >   </tr>
124 >   <tr>
125 >     <td>[[Know/TopicClassification]]</td>
126 >     <td> select </td>
127 >     <td align="center"> 1 </td>
128 >     <td>[[Know/NoDisclosure]], [[Know/PublicSupported]], [[Know/PublicFAQ]]</td>
129 >     <td> blah blah... </td>
130 >   </tr>
131 >   <tr>
132 >     <td>[[Know/OperatingSystem]]</td>
133 >     <td> checkbox </td>
134 >     <td align="center"> 3 </td>
135 >     <td>[[Know/OsHPUX]], [[Know/OsLinux]], [[Know/OsSolaris]], [[Know/OsWin]]</td>
136 >     <td> blah blah... </td>
137 >   </tr>
138 >   <tr>
139 >     <td>[[Know/OsVersion]]</td>
140 >     <td> text </td>
141 >     <td align="center"> 16 </td>
142 >     <td>   </td>
143 >     <td> blah blah... </td>
144 >   </tr>
145 > </table>
146
147 ### <a name="Defining a Form with Multiple To"></a> Defining a Form with Multiple Topics
148
149 Forms can also be defined by using form templates that retrieve field values from one or more separate topics:
150
151 - A <code>**FormTemplate**</code> topic defines the Form, ex: <code>**YourFormTemplate**</code>.
152 - For each field that has a value list - select, radio, checkbox - can use separate topic to define the available values.
153
154 > **Example: WebFormTemplate**
155 >
156 > - Know.WebFormTemplate main definition: <br />   <table border="1" cellpadding="0" cellspacing="0">
157 >   <tr>
158 >     <th bgcolor="#99CCCC"><strong> Name </strong></th>
159 >     <th bgcolor="#99CCCC"><strong> Type </strong></th>
160 >     <th bgcolor="#99CCCC"><strong> Size </strong></th>
161 >     <th bgcolor="#99CCCC"><strong> Values </strong></th>
162 >     <th bgcolor="#99CCCC"><strong> Tooltip message </strong></th>
163 >   </tr>
164 >   <tr>
165 >     <td>[[Know/TopicClassification]]</td>
166 >     <td> select </td>
167 >     <td> 1 </td>
168 >     <td>   </td>
169 >     <td> blah blah... </td>
170 >   </tr>
171 >   <tr>
172 >     <td>[[Know/OperatingSystem]]</td>
173 >     <td> checkbox </td>
174 >     <td> 3 </td>
175 >     <td>   </td>
176 >     <td> blah blah... </td>
177 >   </tr>
178 >   <tr>
179 >     <td>[[Know/OsVersion]]</td>
180 >     <td> text </td>
181 >     <td> 16 </td>
182 >     <td>   </td>
183 >     <td> blah blah... </td>
184 >   </tr>
185 > </table>
186 > <br /> %X% Leave the <code>**Values**</code> field **blank**.
187 >
188 > - Know.TopicClassification field value definition: <br />   <table border="1" cellpadding="0" cellspacing="0">
189 >   <tr>
190 >     <th bgcolor="#99CCCC"><strong> Name </strong></th>
191 >     <th bgcolor="#99CCCC"><strong> Type </strong></th>
192 >     <th bgcolor="#99CCCC"><strong> Tooltip message </strong></th>
193 >   </tr>
194 >   <tr>
195 >     <td>[[Know/NoDisclosure]]</td>
196 >     <td> option </td>
197 >     <td> blah blah... </td>
198 >   </tr>
199 >   <tr>
200 >     <td>[[Know/PublicSupported]]</td>
201 >     <td> option </td>
202 >     <td> blah blah... </td>
203 >   </tr>
204 >   <tr>
205 >     <td>[[Know/PublicFAQ]]</td>
206 >     <td> option </td>
207 >     <td> blah blah... </td>
208 >   </tr>
209 > </table>
210
211 - **Implementation Notes:** This format allows you to define field items with or without [[WikiNames]], depending on your needs.
212   - Topics can be protected in the usual manner, using [[TWikiAccessControl]], to limit who can change the form template and/or individual value lists.
213   - <code>**\[[...]]**</code> links can be used to force a link (at present, the <code>**\[[...]\[...]]**</code> format is not supported).
214   - The <code>**Tooltip message**</code> column is used as a tooltip for the field name (only if field name is a [[WikiName]]) - you only see the tooltip In edit.
215   - The first item in the list is the default item. Alternative initial values can be set in a topic template, like <code>**WebTopicEditTemplate**</code>, with <code>**field=value**</code>, or, for checkboxes, <code>**field=1**</code>.
216   - The topic definition is not read when a topic is viewed.
217
218 <a name="EnablingForms"></a>
219
220 ## <a name="Enabling Forms by Web"></a> Enabling Forms by Web
221
222 Forms are enabled on a per web basis. The <code>**WEBFORMS**</code> variable in [[WebPreferences]] is optional and defines a list of possible form templates. Example:
223
224 - Set WEBFORMS = BugForm, FeatureForm, BookLoanForm
225
226 - With <code>**WEBFORMS**</code> 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.
227
228 ## <a name="Including Forms in New Topics"></a> Including Forms in New Topics
229
230 - A default Form Template (new topics get this default form) can be provided by creating the `WebTopicEditTemplate` topic in a web and adding a form to it. Initial Form values can be set there.
231
232 - Additionally a new topic can be given a Form using the `formtemplate` parameter in the URL. Initial values can then be provided in the URLs or as form values:
233   - other than checkboxes: <code>**name**</code>, ex: <code>**?BugPriority=1**</code>
234   - checkbox: <code>**namevalue=1**</code>, ex: <code>**?ColourRed=1**</code>. <br /> Boxes with a tick must be specified.
235
236 ## <a name="Setting Up Multiple Form Options"></a> Setting Up Multiple Form Options
237
238 - The optional <code>**WEBFORMS**</code> variable defines alternative forms that can be selected by pressing **Change** in edit mode.
239
240 - A topic template can use any form.
241
242 - 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.
243
244 ## <a name="Form Data Storage"></a> Form Data Storage
245
246 The form topic name, fields and values are stored as [[TWikiMetaData]] - the order of the field/value pairs is the same as in the template.
247
248 <a name="UsingFormData"></a>
249
250 ## <a name="Using Form Data"></a> Using Form Data
251
252 [[TWikiForms]] 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]], <code>**SEARCH**</code> and <code>**METASEARCH**</code> variables in [[TWikiVariables]], and [[TWiki Formatted Search|Main/FormattedSearch]] for various options.
253
254 <a name="FormsVsCategoryTables"></a>
255
256 ## <a name="Main Changes from Category Table"></a> Main Changes from Category Tables
257
258 The Form Template system is a more powerful, flexible replacement for the original TWikiCategoryTable. Data from existing category tables can be imported directly.
259
260 <table border="1" cellpadding="0" cellspacing="0">
261   <tr>
262     <th align="center" bgcolor="#99CCCC"><strong> Form Templates </strong></th>
263     <th align="center" bgcolor="#99CCCC"><strong> Category Tables </strong></th>
264   </tr>
265   <tr>
266     <td align="center"> defined in topics </td>
267     <td align="center"> defined in templates </td>
268   </tr>
269   <tr>
270     <td align="center"> many forms per web </td>
271     <td align="center"> one table per web </td>
272   </tr>
273   <tr>
274     <td align="center"> saved as Meta Data </td>
275     <td align="center"> saved as HTML </td>
276   </tr>
277   <tr>
278     <td align="center"><strong>Change</strong> &amp; <strong>Add Form</strong> buttons </td>
279     <td align="center"><strong>UseCategory</strong> radio button </td>
280   </tr>
281 </table>
282
283 ### <a name="Importing Category Table Data"></a> Importing Category Table Data
284
285 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 <code>**twikicatitems.tmpl**</code>. 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.
286
287 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.
288
289 %T% **NOTE:** If things aren't working correctly, there may be useful entries in `data/warning.txt`.
290
291 -- TWiki:Main.JohnTalintyre - 16 Aug 2001 %BR% -- TWiki:Main.MikeMannix - 05 Jan 2002 %BR% -- TWiki:Main.PeterThoeny - 25 Apr 2004