none
[openafs-wiki.git] / TWiki / TWikiForms.mdwn
1 <div>
2   <ul>
3     <li><a href="#Form Templates"> Form Templates</a><ul>
4         <li><a href="#Overview"> Overview</a></li>
5         <li><a href="#Goodby to _TWikiCategoryTables"> Goodby to TWikiCategoryTables </a><ul>
6             <li><a href="#Changes from the Category Table"> Changes from the Category Table System</a></li>
7             <li><a href="#Migrating Existing Category Tabl"> Migrating Existing Category Table Data</a></li>
8           </ul>
9         </li>
10         <li><a href="#Form Template Elements"> Form Template Elements</a><ul>
11             <li><a href="#Defining a Form Template"> Defining a Form Template</a></li>
12             <li><a href="#Examples"> Examples</a></li>
13             <li><a href="#Defining a Form in One Topic"> Defining a Form in One Topic</a></li>
14             <li><a href="#Defining a Form in Multiple Topi"> Defining a Form in Multiple Topics</a></li>
15             <li><a href="#Notes"> Notes</a></li>
16           </ul>
17         </li>
18         <li><a href="#Specification"> Specification</a><ul>
19             <li><a href="#Enabling Forms for a Web"> Enabling Forms for a Web</a></li>
20           </ul>
21         </li>
22         <li><a href="#Creating New Topics with Forms"> Creating New Topics with Forms</a></li>
23         <li><a href="#Setting Up Multiple Form Options"> Setting Up Multiple Form Options</a></li>
24         <li><a href="#Form Template Data Storage"> Form Template Data Storage</a></li>
25       </ul>
26     </li>
27   </ul>
28 </div>
29
30 ## <a name="Form Templates"></a> Form Templates
31
32 Topics allow for flexible free format data, sometimes you want to ensure strucutre to some of the topic information, this can be done with Forms e.g. saying what type of topic it is (e.g. Bug, Feature, FAQ entry etc) and then filling in fields using dropdowns, radio buttons etc.
33
34 ### <a name="Overview"></a> Overview
35
36 If forms are enabled for a Web and a topic has a form you will see it as a table when viewing the page. When you edit you will see the various edit controls below the normal text area. There will be a button at the top of the form marked _Change_ which allows you to change to a different form, or remove the form. If you edit a topic without a form, there will be a button _Add Form_, that let's you associate a form with the topic; note that changes you have made to the topic are not lost when you select this option.
37
38 You can search for topics with specific form data using the %SEARCH% variable - see [[TWikiVariables|Main/TWikiDocumentation#TWikiVariables]].
39
40 ### <a name="Goodby to _TWikiCategoryTables"></a> Goodby to TWikiCategoryTables
41
42 This is a more general replacement for the [[TWikiCategoryTable]] capability, in particular Forms are defined by special topics, where as categories were defineind using special templates.
43
44 #### <a name="Changes from the Category Table"></a><a name="Changes from the Category Table "></a> Changes from the Category Table System
45
46 Main changes from TWikiCategoryTable: The templates for category view/edit have been dropped.and render to HTML on viewing
47
48 <table border="1" cellpadding="0" cellspacing="0">
49   <tr>
50     <th bgcolor="#99CCCC"><strong> Form Templates </strong></th>
51     <th bgcolor="#99CCCC"><strong> Category Tables </strong></th>
52   </tr>
53   <tr>
54     <td> defined by topics </td>
55     <td> defined in a template file </td>
56   </tr>
57   <tr>
58     <td> multiple forms per web </td>
59     <td> one category per web </td>
60   </tr>
61   <tr>
62     <td> data saved in Meta variables </td>
63     <td> data saved as HTML </td>
64   </tr>
65   <tr>
66     <td> [Change] form and [Add Form] contol buttons </td>
67     <td> UseCategory radio button </td>
68   </tr>
69 </table>
70
71 #### <a name="Migrating Existing Category Tabl"></a> Migrating Existing Category Table Data
72
73 The new Form Template system should work with old Category Table data with no special conversion. Old data should be transparently upgraded to the new Meta format when a page imported from the old TWiki is edited and saved in the new system for the first time.
74
75 On upgrading, the administrator must produce a form template topic for each web that uses the old Category Tables. `twikicatitems.tmpl` defines the categories and is used in the conversion. The form template must be set as the first item in the [[WebPreferences]] variable `=WEBFORM`. If it's not present, `view` works, but `edit` results in an _oops_ dialog result. If things aren't working correctly, there may be entries in `data/warning.txt`.
76
77 ### <a name="Form Template Elements"></a> Form Template Elements
78
79 - **Form Template:** A set of fields defining a form. (_Class_ in OO speak; used to be called _category table definition_)
80   - A web may contain more then zero or more form template.
81 - **Form:** A topic containing additional meta-data (besides the free form TEXTAREA) which categorizes the content. (_Object_ in OO speak; used to be called _category table_)
82   - A topic has zero or one of the defined forms. So there are topics with a form or without.
83 - **Form Field:** A named item in a form. (Used to be called _category item name_)
84 - **Field Type:** The type of a field when editing a form. The type defines the HTML INPUT tag widgets when editing a topic:
85   - **select:** Drop down box or selector
86   - **checkbox:** One or more check boxes
87   - **checkbox+buttons:** One or more check boxes, plus _set_ and _clear_ buttons to set/clear all check boxes
88   - **radio:** One or more radio buttons
89   - **text:** A one-line text field
90   - **textarea:** A general text area - size is _rows_x_cols_ e.g. 40x10
91 - **Field Value:** Value of a form field. Can be one or more values from a fixed set (select, checkbox, radio type) or free form (text type). (Used to be called _category item value_)
92
93 #### <a name="Defining a Form Template"></a> Defining a Form Template
94
95 Form templates are defined by topics, one topic per form template. A form template topic has descriptive text mixed with the form template definition in the form of a TWiki table.
96
97 #### <a name="Examples"></a> Examples
98
99 #### <a name="Defining a Form in One Topic"></a> Defining a Form in One Topic
100
101 Example: WebFormTemplate of the TWiki.Know web:
102
103 <table border="1" cellpadding="0" cellspacing="0">
104   <tr>
105     <th bgcolor="#99CCCC"><strong> Name: </strong></th>
106     <th bgcolor="#99CCCC"><strong> Type: </strong></th>
107     <th bgcolor="#99CCCC"><strong> Size: </strong></th>
108     <th bgcolor="#99CCCC"><strong> Values: </strong></th>
109     <th bgcolor="#99CCCC"><strong> Tooltip message: </strong></th>
110   </tr>
111   <tr>
112     <td>[[Know/TopicClassification]]</td>
113     <td> select </td>
114     <td> 1 </td>
115     <td>[[Know/NoDisclosure]], [[Know/PublicSupported]], [[Know/PublicFAQ]]</td>
116     <td> blah blah... </td>
117   </tr>
118   <tr>
119     <td>[[Know/OperatingSystem]]</td>
120     <td> checkbox </td>
121     <td> 3 </td>
122     <td>[[Know/OsHPUX]], [[Know/OsLinux]], [[Know/OsSolaris]], [[Know/OsWin]]</td>
123     <td> blah blah... </td>
124   </tr>
125   <tr>
126     <td>[[Know/OsVersion]]</td>
127     <td> text </td>
128     <td> 16 </td>
129     <td>   </td>
130     <td> blah blah... </td>
131   </tr>
132 </table>
133
134 #### <a name="Defining a Form in Multiple Topi"></a> Defining a Form in Multiple Topics
135
136 The form template can also be defined in an alternative way by using more then one topic:
137
138 - A **form template topic** defines the form
139 - Values of fields that have more then one value, e.g. of type radio, select and checkbox can be defined by **field value template topics**
140
141 Above Example:
142
143 - WebFormTemplate of the TWiki.Know web: <table border="1" cellpadding="0" cellspacing="0">
144   <tr>
145     <th bgcolor="#99CCCC"><strong> Name: </strong></th>
146     <th bgcolor="#99CCCC"><strong> Type: </strong></th>
147     <th bgcolor="#99CCCC"><strong> Size: </strong></th>
148     <th bgcolor="#99CCCC"><strong> Values: </strong></th>
149     <th bgcolor="#99CCCC"><strong> Tooltip message: </strong></th>
150   </tr>
151   <tr>
152     <td>[[Know/TopicClassification]]</td>
153     <td> select </td>
154     <td> 1 </td>
155     <td>   </td>
156     <td> blah blah... </td>
157   </tr>
158   <tr>
159     <td>[[Know/OperatingSystem]]</td>
160     <td> checkbox </td>
161     <td> 3 </td>
162     <td>   </td>
163     <td> blah blah... </td>
164   </tr>
165   <tr>
166     <td>[[Know/OsVersion]]</td>
167     <td> text </td>
168     <td> 16 </td>
169     <td>   </td>
170     <td> blah blah... </td>
171   </tr>
172 </table>
173
174 - TopicClassification topic: <table border="1" cellpadding="0" cellspacing="0">
175   <tr>
176     <th bgcolor="#99CCCC"><strong> Name: </strong></th>
177     <th bgcolor="#99CCCC"><strong> Type: </strong></th>
178     <th bgcolor="#99CCCC"><strong> Tooltip message: </strong></th>
179   </tr>
180   <tr>
181     <td>[[Know/NoDisclosure]]</td>
182     <td> option </td>
183     <td> blah blah... </td>
184   </tr>
185   <tr>
186     <td>[[Know/PublicSupported]]</td>
187     <td> option </td>
188     <td> blah blah... </td>
189   </tr>
190   <tr>
191     <td>[[Know/PublicFAQ]]</td>
192     <td> option </td>
193     <td> blah blah... </td>
194   </tr>
195 </table>
196
197 #### <a name="Notes"></a> Notes
198
199 - This format allows you to define field items with / without [[WikiNames]], depending on your needs.
200 - The topic can be protected in the usual manner so that not everybody can change the form template - see [[TWikiAccessControl]]
201 - <code>[[...|/WebHome]]</code> can be used for force a link, at present <code>[[...|/WebHome]]</code> format is not supported
202 - 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
203 - The first item in the list is the default item. Alternative initial values can be given in a topic template such as <code>**WebTopicEditTemplate**</code> or using fieldFLD=value or for checkboxes fieldFLDcheckbox=1 in URL
204 - The topic definition is not read when a topic is viewed
205
206 ### <a name="Specification"></a> Specification
207
208 #### <a name="Enabling Forms for a Web"></a> Enabling Forms for a Web
209
210 By default topics can be edited in free form. A form can be added to a topic to give it more structure. Forms are enabled on a per web basis.
211
212 The <code>**WEBFORMS**</code> variable in [[WebPreferences]] is optional and defines a list of possible form templates e.g.
213
214 - Set WEBFORMS = BugForm, FeatureForm, BookLoanForm
215
216 With this present 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 to the right of the form name. The buttons leads to a screen that enables _no form_ to be selected of one of those specified by `WEBFORMS`.
217
218 A default form template (i.e. new topics get this default form) can be provided by creating the <code>**WebTopicEditTemplate**</code> topic in a Web and adding a form to it. Initial form values can be set here.
219
220 Addtionaly 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. Names being:
221
222 - Not checkboxs - nameFLD e.g. ?BugPriorityFLD=1
223 - Checkbox - nameFLDvalue=1 e.g. ?ColourFLDRed=1. Note that all boxes with a tick must be specified.
224
225 ### <a name="Creating New Topics with Forms"></a> Creating New Topics with Forms
226
227 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. If the [[WebTopicEditTemplate]] topic has a form added, the form will appear with values set; press [Change] to remove the template or to switch to a different one.
228
229 A form embedded in a topic also appears in a new topic. This is done by specifying the `formtemplate` parameter in the URL.
230
231 ### <a name="Setting Up Multiple Form Options"></a> Setting Up Multiple Form Options
232
233 - The optional <code>**WEBFORMS**</code> variable defines alternative Form Templates that can be selected after pressing [Change] button on the Edit page
234 - A template topic can use any form template
235 - Decided not to ask user to choose a template or form template when creating a topic as goes against the KISS of Wiki systems.
236 - New topics with a form get instantiated by simple HTML forms asking for a topic name. If there is a SubmitExpenseReport topic were you can create new expense reports, a SubmitVacationRequest topic and so on. These can specify the required template topic and hence form. **_HUH?_**
237
238 ### <a name="Form Template Data Storage"></a> Form Template Data Storage
239
240 The Form Template topic name, fields and values are stored in the topic [[Meta Data|Main/TWikiDocumentation#TWikiMetaData]]. The order of field/value pairs in the Meta Data is the same as in the Template. The Form name is required for [Edit] and [Save]. -- [[JohnTalintyre]] - 16 Aug 2001 <br />