b460a26a4c4c33ea66d0f2b7e566e1bc578944c8
[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="#Main Changes from Category Table"> Main Changes from Category Tables</a><ul>
6             <li><a href="#Importing Category Table Data"> Importing Category Table Data</a></li>
7           </ul>
8         </li>
9         <li><a href="#Defining a Form Template"> Defining a Form Template</a><ul>
10             <li><a href="#Form Template Elements"> Form Template Elements</a></li>
11             <li><a href="#Defining a Form in One Topic"> Defining a Form in One Topic</a></li>
12             <li><a href="#Defining a Form with Multiple To"> Defining a Form with Multiple Topics</a></li>
13           </ul>
14         </li>
15         <li><a href="#Enabling Forms by Web"> Enabling Forms by Web</a></li>
16         <li><a href="#Including Forms in New Topics"> Including Forms in New Topics</a></li>
17         <li><a href="#Setting Up Multiple Form Options"> Setting Up Multiple Form Options</a></li>
18         <li><a href="#Form Template Data Storage"> Form Template Data Storage</a></li>
19       </ul>
20     </li>
21   </ul>
22 </div>
23
24 # <a name="TWiki Forms"></a> TWiki Forms
25
26 _Form-based input in topics, with name/value pairs stored as Meta Data variables; multiple forms per web &amp; topic_
27
28 ## <a name="Overview"></a> Overview
29
30 By adding form-based input to free-form content, you can structure topics with unlimited, easily searchable categories. When forms are enabled for a web and selected in a topic, the form appears in edit mode, and the contents are rendered as a table when viewing the actual page. When editing, can switch forms, if more than one is defined, or remove forms entirely. Form input values are stored as [[TWikiMetaData]]; all data is saved.
31
32 Form Templates replace TWikiCategory Tables from the 01-Dec-2000 version of TWiki.
33
34 <a name="FormsVsCategoryTables"></a>
35
36 ## <a name="Main Changes from Category Table"></a> Main Changes from Category Tables
37
38 Form Templates more powerful, flexible replacement for the original TWikiCategoryTable. Data from existing category tables can be imported directly.
39
40 <table border="1" cellpadding="0" cellspacing="0">
41   <tr>
42     <th align="center" bgcolor="#99CCCC"><strong> Form Templates </strong></th>
43     <th align="center" bgcolor="#99CCCC"><strong> Category Tables </strong></th>
44   </tr>
45   <tr>
46     <td align="center"> defined in topics </td>
47     <td align="center"> defined in templates </td>
48   </tr>
49   <tr>
50     <td align="center"> many forms per web </td>
51     <td align="center"> one table per web </td>
52   </tr>
53   <tr>
54     <td align="center"> saved as Meta Data </td>
55     <td align="center"> saved as HTML </td>
56   </tr>
57   <tr>
58     <td align="center"><strong>Change</strong> &amp; <strong>Add Form</strong> buttons </td>
59     <td align="center"><strong>UseCategory</strong> radio button </td>
60   </tr>
61 </table>
62
63 ### <a name="Importing Category Table Data"></a> Importing Category Table Data
64
65 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.
66
67 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.
68
69 **_NOTE:_** If things aren't working correctly, there may be useful entries in `data/warning.txt`.
70
71 ## <a name="Defining a Form Template"></a> Defining a Form Template
72
73 A Form Template is simply a page containing your form, defined in a table where each row is one form field.
74
75 ### <a name="Form Template Elements"></a> Form Template Elements
76
77 - **form template** - a set of fields defining a form (replaces _category table definition_)
78   - A web can use one or more form templates.
79 - **form** - A topic containing additional meta-data (besides the free form TEXTAREA) which categorizes the content. (replaces _category table_)
80   - A topic has zero or one of the defined forms. So there are topics with a form or without.
81 - **form field** - a named item in a form (replaces _category item name_)
82 - **field type** - selects the INPUT type:
83   - **select** - drop-down menu or scrollable box
84   - **checkbox** - one or more checkboxes
85   - **checkbox+buttons** - one or more checkboxes, plus **Set** and **Clear** buttons
86   - **radio** - one or more radio buttons
87   - **text** - a one-line text field
88   - **textarea** - a text box; size is 40x10 (columns x rows)
89 - **field value** - one or more values from a fixed set (select, checkbox, radio type) or free-form (text). (replaces _category item value_)
90
91 ### <a name="Defining a Form in One Topic"></a> Defining a Form in One Topic
92
93 1. Create a new topic with your Form name: MyForm, ExpenseReport, InfoCategory, RecordReview, whatever you need.
94 2. Create a TWiki table, with each column representing one element of an entry field: Name, Type, Size, Values, and Tooltip msessage (see sample below).
95 3. For each field, fill in a new line; for the type of field, select from the list.
96 4. Save the topic.
97
98 > **Example: WebForm from the TWiki.Know web**
99 >
100 >     | *Name* | *Type* | *Size* | *Values* | *Tooltip message* |
101 >     | Know.TopicClassification | select | 1 | Know.NoDisclosure,
102 >       Know.PublicSupported, Know.PublicFAQ | blah blah... |
103 >     | Know.OperatingSystem | checkbox | 3 | Know.OsHPUX, Know.OsLinux,
104 >       Know.OsSolaris, Know.OsWin | blah blah... |
105 >     | Know.OsVersion | text | 16 | | blah blah... |
106 >
107 > <table border="1" cellpadding="0" cellspacing="0">
108 >   <tr>
109 >     <th bgcolor="#99CCCC"><strong> Name </strong></th>
110 >     <th bgcolor="#99CCCC"><strong> Type </strong></th>
111 >     <th bgcolor="#99CCCC"><strong> Size </strong></th>
112 >     <th bgcolor="#99CCCC"><strong> Values </strong></th>
113 >     <th bgcolor="#99CCCC"><strong> Tooltip message </strong></th>
114 >   </tr>
115 >   <tr>
116 >     <td>[[Know/TopicClassification]]</td>
117 >     <td> select </td>
118 >     <td align="center"> 1 </td>
119 >     <td>[[Know/NoDisclosure]], [[Know/PublicSupported]], [[Know/PublicFAQ]]</td>
120 >     <td> blah blah... </td>
121 >   </tr>
122 >   <tr>
123 >     <td>[[Know/OperatingSystem]]</td>
124 >     <td> checkbox </td>
125 >     <td align="center"> 3 </td>
126 >     <td>[[Know/OsHPUX]], [[Know/OsLinux]], [[Know/OsSolaris]], [[Know/OsWin]]</td>
127 >     <td> blah blah... </td>
128 >   </tr>
129 >   <tr>
130 >     <td>[[Know/OsVersion]]</td>
131 >     <td> text </td>
132 >     <td align="center"> 16 </td>
133 >     <td>   </td>
134 >     <td> blah blah... </td>
135 >   </tr>
136 > </table>
137
138 ### <a name="Defining a Form with Multiple To"></a> Defining a Form with Multiple Topics
139
140 The Form Template can also be defined in an alternative way by using more then one topic:
141
142 - A Form Template topic defines the Form.
143 - Fields that have more then one value - radio, select, checkbox - can be defined in individual field value topics.
144
145 > **Example: WebFormTemplate**
146 >
147 > - Know.WebFormTemplate Form main definition: <br />   <table border="1" cellpadding="0" cellspacing="0">
148 >   <tr>
149 >     <th bgcolor="#99CCCC"><strong> Name </strong></th>
150 >     <th bgcolor="#99CCCC"><strong> Type </strong></th>
151 >     <th bgcolor="#99CCCC"><strong> Size </strong></th>
152 >     <th bgcolor="#99CCCC"><strong> Values </strong></th>
153 >     <th bgcolor="#99CCCC"><strong> Tooltip message </strong></th>
154 >   </tr>
155 >   <tr>
156 >     <td>[[Know/TopicClassification]]</td>
157 >     <td> select </td>
158 >     <td> 1 </td>
159 >     <td align="center"> ... </td>
160 >     <td> blah blah... </td>
161 >   </tr>
162 >   <tr>
163 >     <td>[[Know/OperatingSystem]]</td>
164 >     <td> checkbox </td>
165 >     <td> 3 </td>
166 >     <td align="center"> ... </td>
167 >     <td> blah blah... </td>
168 >   </tr>
169 >   <tr>
170 >     <td>[[Know/OsVersion]]</td>
171 >     <td> text </td>
172 >     <td> 16 </td>
173 >     <td align="center"> ... </td>
174 >     <td> blah blah... </td>
175 >   </tr>
176 > </table>
177 >
178 > - Know.TopicClassification field value definition: <br />   <table border="1" cellpadding="0" cellspacing="0">
179 >   <tr>
180 >     <th bgcolor="#99CCCC"><strong> Name </strong></th>
181 >     <th bgcolor="#99CCCC"><strong> Type </strong></th>
182 >     <th bgcolor="#99CCCC"><strong> Tooltip message </strong></th>
183 >   </tr>
184 >   <tr>
185 >     <td>[[Know/NoDisclosure]]</td>
186 >     <td> option </td>
187 >     <td> blah blah... </td>
188 >   </tr>
189 >   <tr>
190 >     <td>[[Know/PublicSupported]]</td>
191 >     <td> option </td>
192 >     <td> blah blah... </td>
193 >   </tr>
194 >   <tr>
195 >     <td>[[Know/PublicFAQ]]</td>
196 >     <td> option </td>
197 >     <td> blah blah... </td>
198 >   </tr>
199 > </table>
200
201 - **Implementation Notes:** This format allows you to define field items with or without [[WikiNames]], depending on your needs.
202   - The topic can be protected in the usual manner so that not everybody can change the form template - see [[TWikiAccessControl]]
203   - `[[...]]` links can be used for force a link, at present `[[...][...]]` format is not supported.
204   - The "Tooltip message" column is used as a tool tip for the field name (only if field name is a [[WikiName]]) - you only see the tooltip on edit.
205   - The first item in the list is the default item. Alternative initial values can be given in a topic template such as `WebTopicEditTemplate` or using field=value or for checkboxes field=1.
206   - The topic definition is not read when a topic is viewed.
207
208 ## <a name="Enabling Forms by Web"></a> Enabling Forms by Web
209
210 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:
211
212 - Set WEBFORMS = BugForm, FeatureForm, BookLoanForm
213
214 - 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.
215
216 - 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.
217
218 - 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:
219   - other than checkboxes: `name`, ex: `?BugPriority=1`
220   - checkbox: `namevalue=1`, ex: `?ColourRed=1`. <br /> Boxes with a tick must be specified.
221
222 ## <a name="Including Forms in New Topics"></a> Including Forms in New Topics
223
224 When you create a new topic in a web that has the WEBFORMS Preferences variable set, an **Add Form** button appears at the bottom of the page. You can start all new topics with forms enabled, and pre-select a form if there's more than one available:
225
226 1. **Edit** the [[WebTopicEditTemplate]] topic, adding the name of an available Form.
227 2. **Create** a new topic to check - the Form should appear with values set.
228   - Click **Change** to switch or remove Forms.
229
230 A form embedded in a topic also appears in a new topic. This is done by specifying the `formtemplate` parameter in the URL.
231
232 ## <a name="Setting Up Multiple Form Options"></a> Setting Up Multiple Form Options
233
234 - The optional <code>**WEBFORMS**</code> variable defines alternative Form Templates that can be selected by pressing **Change** in edit mode.
235
236 - A Template topic can use any Form Template.
237
238 - 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.
239
240 ## <a name="Form Template Data Storage"></a> Form Template Data Storage
241
242 The Form Template topic name, fields and values are stored as [[TWikiMetaData]]. The order of field/value pairs in the Meta Data is the same as in the Template.
243
244 -- [[JohnTalintyre]] - 16 Aug 2001 <br /> -- [[MikeMannix]] - 03 Dec 2001