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="#TWikiCategoryTables Are History"> TWikiCategoryTables Are History</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="#Defining a Form in One Topic"> Defining a Form in One Topic</a></li>
13             <li><a href="#Defining a Form in Multiple Topi"> Defining a Form in Multiple Topics</a></li>
14             <li><a href="#Various Implementation Notes"> Various Implementation Notes</a></li>
15           </ul>
16         </li>
17         <li><a href="#Enabling Forms by Web"> Enabling Forms by Web</a></li>
18         <li><a href="#Creating New Topics with Forms"> Creating New Topics with Forms</a></li>
19         <li><a href="#Setting Up Multiple Form Options"> Setting Up Multiple Form Options</a></li>
20         <li><a href="#Form Template Data Storage"> Form Template Data Storage</a></li>
21       </ul>
22     </li>
23   </ul>
24 </div>
25
26 ## <a name="Form Templates"></a> Form Templates
27
28 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.
29
30 ### <a name="Overview"></a> Overview
31
32 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.
33
34 You can search for topics with specific form data using the %SEARCH% variable - see [[TWikiVariables|Main/TWikiDocumentation#TWikiVariables]].
35
36 ### <a name="TWikiCategoryTables Are History"></a><a name="_TWikiCategoryTables Are History"></a> TWikiCategoryTables Are History
37
38 Form Templates more powerful, flexible replacement for the original TWikiCategoryTable.
39
40 #### <a name="Changes from the Category Table"></a><a name="Changes from the Category Table "></a> Changes from the Category Table System
41
42 Main changes from TWikiCategoryTable: The templates for category view/edit have been dropped, and the forma renders to HTML on viewing.
43
44 <table border="1" cellpadding="0" cellspacing="0">
45   <tr>
46     <th bgcolor="#99CCCC"><strong> Form Templates </strong></th>
47     <th bgcolor="#99CCCC"><strong> Category Tables </strong></th>
48   </tr>
49   <tr>
50     <td> defined by topics </td>
51     <td> defined in a template file </td>
52   </tr>
53   <tr>
54     <td> multiple forms per web </td>
55     <td> one category per web </td>
56   </tr>
57   <tr>
58     <td> data saved in Meta variables </td>
59     <td> data saved as HTML </td>
60   </tr>
61   <tr>
62     <td> [Change] form and [Add Form] contol buttons </td>
63     <td> UseCategory radio button </td>
64   </tr>
65 </table>
66
67 #### <a name="Migrating Existing Category Tabl"></a> Migrating Existing Category Table Data
68
69 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.
70
71 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`.
72
73 ### <a name="Form Template Elements"></a> Form Template Elements
74
75 - **Form Template:** A set of fields defining a form. (_Class_ in OO speak; used to be called _category table definition_)
76   - A web may contain more then zero or more form template.
77 - **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_)
78   - A topic has zero or one of the defined forms. So there are topics with a form or without.
79 - **Form Field:** A named item in a form. (Used to be called _category item name_)
80 - **Field Type:** The type of a field when editing a form. The type defines the HTML INPUT tag widgets when editing a topic:
81   - **select:** Drop down box or selector
82   - **checkbox:** One or more check boxes
83   - **checkbox+buttons:** One or more check boxes, plus [Set] and []\[Clear] buttons to set/clear all checkboxes
84   - **radio:** One or more radio buttons
85   - **text:** A one-line text field
86   - **textarea:** A general text area - size is _rows_x_cols_ 40x10
87 - **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_)
88
89 #### <a name="Defining a Form Template"></a> Defining a Form Template
90
91 A Form Template is simply a page containing your form, defined in a table where each row is one form field.
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 > <span><font>**Example:** Form Template </font></span>
99 >
100 >     | *Name:* | *Type:* | *Size:* | *Values:* | *Tooltip message:* |
101 >     | TopClass | select | 1 | Select one..., Private, Public | must fill |
102 >     | Target   | checkbox+buttons | 3 | 1, No.2, No.3 | Select OS |
103 >     | Version | text | 16 | | OS version |
104
105 #### <a name="Defining a Form in One Topic"></a> Defining a Form in One Topic
106
107 Example: WebFormTemplate of the TWiki.Know web:
108
109 <table border="1" cellpadding="0" cellspacing="0">
110   <tr>
111     <th bgcolor="#99CCCC"><strong> Name: </strong></th>
112     <th bgcolor="#99CCCC"><strong> Type: </strong></th>
113     <th bgcolor="#99CCCC"><strong> Size: </strong></th>
114     <th bgcolor="#99CCCC"><strong> Values: </strong></th>
115     <th bgcolor="#99CCCC"><strong> Tooltip message: </strong></th>
116   </tr>
117   <tr>
118     <td>[[Know/TopicClassification]]</td>
119     <td> select </td>
120     <td> 1 </td>
121     <td>[[Know/NoDisclosure]], [[Know/PublicSupported]], [[Know/PublicFAQ]]</td>
122     <td> blah blah... </td>
123   </tr>
124   <tr>
125     <td>[[Know/OperatingSystem]]</td>
126     <td> checkbox </td>
127     <td> 3 </td>
128     <td>[[Know/OsHPUX]], [[Know/OsLinux]], [[Know/OsSolaris]], [[Know/OsWin]]</td>
129     <td> blah blah... </td>
130   </tr>
131   <tr>
132     <td>[[Know/OsVersion]]</td>
133     <td> text </td>
134     <td> 16 </td>
135     <td>   </td>
136     <td> blah blah... </td>
137   </tr>
138 </table>
139
140 #### <a name="Defining a Form in Multiple Topi"></a> Defining a Form in Multiple Topics
141
142 The form template can also be defined in an alternative way by using more then one topic:
143
144 - A **form template topic** defines the form
145 - 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**
146
147 > <span><font>**Code from:** </font></span>
148 >
149 > - WebFormTemplate of the TWiki.Know web: <table border="1" cellpadding="0" cellspacing="0">
150 >   <tr>
151 >     <th bgcolor="#99CCCC"><strong> Name: </strong></th>
152 >     <th bgcolor="#99CCCC"><strong> Type: </strong></th>
153 >     <th bgcolor="#99CCCC"><strong> Size: </strong></th>
154 >     <th bgcolor="#99CCCC"><strong> Values: </strong></th>
155 >     <th bgcolor="#99CCCC"><strong> Tooltip message: </strong></th>
156 >   </tr>
157 >   <tr>
158 >     <td>[[Know/TopicClassification]]</td>
159 >     <td> select </td>
160 >     <td> 1 </td>
161 >     <td>   </td>
162 >     <td> blah blah... </td>
163 >   </tr>
164 >   <tr>
165 >     <td>[[Know/OperatingSystem]]</td>
166 >     <td> checkbox </td>
167 >     <td> 3 </td>
168 >     <td>   </td>
169 >     <td> blah blah... </td>
170 >   </tr>
171 >   <tr>
172 >     <td>[[Know/OsVersion]]</td>
173 >     <td> text </td>
174 >     <td> 16 </td>
175 >     <td>   </td>
176 >     <td> blah blah... </td>
177 >   </tr>
178 > </table>
179 >
180 > - TopicClassification topic: <table border="1" cellpadding="0" cellspacing="0">
181 >   <tr>
182 >     <th bgcolor="#99CCCC"><strong> Name: </strong></th>
183 >     <th bgcolor="#99CCCC"><strong> Type: </strong></th>
184 >     <th bgcolor="#99CCCC"><strong> Tooltip message: </strong></th>
185 >   </tr>
186 >   <tr>
187 >     <td>[[Know/NoDisclosure]]</td>
188 >     <td> option </td>
189 >     <td> blah blah... </td>
190 >   </tr>
191 >   <tr>
192 >     <td>[[Know/PublicSupported]]</td>
193 >     <td> option </td>
194 >     <td> blah blah... </td>
195 >   </tr>
196 >   <tr>
197 >     <td>[[Know/PublicFAQ]]</td>
198 >     <td> option </td>
199 >     <td> blah blah... </td>
200 >   </tr>
201 > </table>
202
203 #### <a name="Various Implementation Notes"></a> Various Implementation Notes
204
205 - This format allows you to define field items with / without [[WikiNames]], depending on your needs.
206 - The topic can be protected in the usual manner so that not everybody can change the form template - see [[TWikiAccessControl]]
207 - <code>[[...|/WebHome]]</code> can be used for force a link, at present <code>[[...|/WebHome]]</code> format is not supported
208 - 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
209 - 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 field=value or for checkboxes field=1
210 - The topic definition is not read when a topic is viewed
211
212 ### <a name="Enabling Forms by Web"></a> Enabling Forms by Web
213
214 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 e.g.
215
216 - Set WEBFORMS = BugForm, FeatureForm, BookLoanForm
217
218 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 lead to a screen that enables _no form_ to be selected or one of those specified by `WEBFORMS`.
219
220 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.
221
222 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:
223
224 - Not checkboxes - name e.g. ?BugPriority=1
225 - Checkbox - namevalue=1 e.g. ?ColourRed=1. Note that all boxes with a tick must be specified.
226
227 ### <a name="Creating New Topics with Forms"></a> Creating New Topics with Forms
228
229 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.
230
231 A form embedded in a topic also appears in a new topic. This is done by specifying the `formtemplate` parameter in the URL.
232
233 ### <a name="Setting Up Multiple Form Options"></a> Setting Up Multiple Form Options
234
235 - The optional <code>**WEBFORMS**</code> variable defines alternative Form Templates that can be selected after pressing [Change] on the Edit page
236 - A template topic can use any form template
237 - 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?_**
238
239 ### <a name="Form Template Data Storage"></a> Form Template Data Storage
240
241 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 />