(no commit message)
[openafs-wiki.git] / TWiki / TWikiFormDotPm.mdwn
1 # <a name="Package &lt;code&gt;TWiki::Form="></a> Package =TWiki::Form
2
3 Object representing a single form definition.
4
5 Form definitions are mainly used to control rendering of a form for editing, though there is some application login there that handles transferring values between edits and saves.
6
7 A form definition consists of a TWiki::Form object, which has a list of field definitions. Each field definition is an object of a type derived from TWiki::Form::FieldDefinition. These objects are responsible for the actual syntax and semantics of the field type. Form definitions are parsed from TWiki tables, and the types are mapped by name to a class declared in TWiki::Form::\* - for example, the `text` type is mapped to `TWiki::Form::Text` and the `checkbox` type to `TWiki::Form::Checkbox`.
8
9 The `TWiki::Form::FieldDefinition` class declares default behaviours for types that accept a single value in their definitions. The `TWiki::Form::ListFieldDefinition` extends this for types that have lists of possible values.
10
11 <div>
12   <ul>
13     <li><a href="#Package =TWiki::Form="> Package TWiki::Form</a><ul>
14         <li><a href="#ClassMethod <strong>new</strong> ($session,$web"> ClassMethod new <tt>($session,$web,$form,$def)</tt></a></li>
15         <li><a href="#ObjectMethod <strong>finish</strong> ()"> ObjectMethod finish <tt>()</tt></a></li>
16         <li><a href="#StaticMethod *field_Title2FieldN"> StaticMethod fieldTitle2FieldName <tt>($title) -&gt; $name</tt></a></li>
17         <li><a href="#ObjectMethod <strong>render_ForEdit</strong> ($"> ObjectMethod renderForEdit <tt>($web,$topic,$meta) -&gt; $html</tt></a></li>
18         <li><a href="#ObjectMethod <strong>renderHidden</strong> ($me"> ObjectMethod renderHidden <tt>($meta) -&gt; $html</tt></a></li>
19         <li><a href="#ObjectMethod *get_FieldValuesFro"> ObjectMethod getFieldValuesFromQuery <tt>($query,$metaObject) -&gt; ($seen,\@missing)</tt></a></li>
20         <li><a href="#ObjectMethod *is_TextMergeable*"> ObjectMethod isTextMergeable <tt>($name) -&gt; $boolean</tt></a></li>
21         <li><a href="#ObjectMethod <strong>getField</strong> ($name)"> ObjectMethod getField <tt>($name) -&gt; $fieldDefinition</tt></a></li>
22         <li><a href="#ObjectMethod <strong>getFields</strong> () -> \"> ObjectMethod getFields <tt>() -&gt; \@fields</tt></a></li>
23       </ul>
24     </li>
25   </ul>
26 </div>
27
28 ## <a name="ClassMethod &lt;strong&gt;new&lt;/strong&gt; ($session,$web"></a> [[ClassMethod]] **new** `($session,$web,$form,$def)`
29
30 Looks up a form in the session object or, if it hasn't been read yet, reads it frm the form definition topic on disc.
31
32 - $web - default web to recover form from, if $form doesn't specify a web
33 - `$form` - topic name to read form definition from
34 - `$def` - optional. a reference to a list of field definitions. if present, these definitions will be used, rather than those in `$form`.
35
36 May throw TWiki::OopsException
37
38 ## <a name="ObjectMethod &lt;strong&gt;finish&lt;/strong&gt; ()"></a> [[ObjectMethod]] **finish** `()`
39
40 Break circular references.
41
42 ## <a name="StaticMethod &lt;strong&gt;field_Title2FieldN"></a> [[StaticMethod]] \*fieldTitle2FieldName `($title) -> $name`
43
44 Chop out all except A-Za-z0-9\_. from a field name to create a valid "name" for storing in meta-data
45
46 ## <a name="ObjectMethod &lt;strong&gt;render_ForEdit&lt;/strong&gt; ($"></a> [[ObjectMethod]] **renderForEdit** `($web,$topic,$meta) -> $html`
47
48 - `$web` the web of the topic being rendered
49 - `$topic` the topic being rendered
50 - `$meta` the meta data for the form
51
52 Render the form fields for entry during an edit session, using data values from $meta
53
54 ## <a name="ObjectMethod &lt;strong&gt;renderHidden&lt;/strong&gt; ($me"></a> [[ObjectMethod]] **renderHidden** `($meta) -> $html`
55
56 Render form fields found in the meta as hidden inputs, so they pass through edits untouched.
57
58 ## <a name="ObjectMethod &lt;strong&gt;get_FieldValuesFro"></a> [[ObjectMethod]] \*getFieldValuesFromQuery `($query,$metaObject) -> ($seen,\@missing)`
59
60 Extract new values for form fields from a query.
61
62 - `$query` - the query
63 - `$metaObject` - the meta object that is storing the form values
64
65 For each field, if there is a value in the query, use it. Otherwise if there is already entry for the field in the meta, keep it.
66
67 Returns the number of fields which had values provided by the query, and a references to an array of the names of mandatory fields that were missing from the query.
68
69 ## <a name="ObjectMethod &lt;strong&gt;is_TextMergeable*"></a><a name="ObjectMethod *is_TextMergeable&lt;/strong&gt; "></a> [[ObjectMethod]] **isTextMergeable** `($name) -> $boolean`
70
71 - `$name` - name of a form field (value of the `name` attribute)
72
73 Returns true if the type of the named field allows it to be text-merged.
74
75 If the form does not define the field, it is assumed to be mergeable.
76
77 ## <a name="ObjectMethod &lt;strong&gt;getField&lt;/strong&gt; ($name)"></a><a name="ObjectMethod &lt;strong&gt;getField&lt;/strong&gt; ($name) "></a> [[ObjectMethod]] **getField** `($name) -> $fieldDefinition`
78
79 - `$name` - name of a form field (value of the `name` attribute)
80
81 Returns a `TWiki::Form::FieldDefinition`, or undef if the form does not define the field.
82
83 ## <a name="ObjectMethod &lt;strong&gt;getFields&lt;/strong&gt; () - \@"></a> [[ObjectMethod]] **getFields** `() -> \@fields`
84
85 Return a list containing references to field name/value pairs. Each entry in the list has a \{name\} field and a \{value\} field. It may have other fields as well, which caller should ignore. The returned list should be treated as **read only** (must not be written to).