File: node20.html

package info (click to toggle)
cherrypy 0.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,324 kB
  • ctags: 1,759
  • sloc: python: 14,411; sh: 6,915; perl: 2,472; makefile: 76
file content (188 lines) | stat: -rw-r--r-- 7,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>1.5.2.4 Form</title>
<META NAME="description" CONTENT="1.5.2.4 Form">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" type='text/css'>
<link rel="first" href="lib.html">
<link rel="contents" href="contents.html" title="Contents">

<LINK REL="previous" HREF="node19.html">
<LINK REL="up" HREF="node16.html">
<LINK REL="next" HREF="node21.html">
<meta name='aesop' content='information'>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node19.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A HREF="node16.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A HREF="node21.html"><img src="../icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Standard Library Reference</td>
<td><A href="contents.html"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node19.html">1.5.2.3 DefaultFormMask</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node16.html">1.5.2 Module</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node21.html">1.5.3 Writing a form</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->

<H3><A NAME="SECTION003524000000000000000">
1.5.2.4 Form</A>
</H3>

<P>
The is the main CherryClass of the module. To create a form, you should declare a CherryClass that inherits from Form.

<P>
You may use the following variables and methods:

<P>
<dl><dt><b><a name="l2h-30"><tt class="member">variable: method</tt></a></b>
<dd>
String containing the <var>method</var> attribute of the form tag. It may be <var>send</var> or <var>post</var>. The default value
is <var>post</var>
</dl>
<dl><dt><b><a name="l2h-31"><tt class="member">variable: enctype</tt></a></b>
<dd>
String containing the <var>enctype</var> attribute of the form tag. For instance, for a form that allows the user to upload
files, you would use <var>multipart/form-data</var> The default value is an empty string, which means that the <var>enctype</var>
attribute wile be omitted.
</dl>
<dl><dt><b><a name="l2h-32"><tt class="member">variable: fieldList</tt></a></b>
<dd>
List containing instances of the FormField and FormInstance CherryClasses. This list determines which fields and
separators will be displayed, and in which order. <var>fieldList</var> should be set in the <var>__init__</var> method of the
CherryClass.
</dl>

<P>
<dl><dt><b><a name="l2h-33"><tt class="function">function: formView</tt></a></b>(<var>leaveValues=0</var>)
<dd>
This function returns the HTML code for the form. if <var>leaveValues</var> is false, it will use the default value
for each of the fields. If <var>leaveValues</var> is true, it will use the values that are in <var>request.paramMap</var> (in other
words, the values that were entered by the user)
</dl>

<P>
<dl><dt><b><a name="l2h-34"><tt class="function">function: validateFields</tt></a></b>()
<dd>
This function should be overwritten if you need to perform some validation that involves several fields at the
same time (for instance, checking that 2 passwords match).

<P>
If a field has an error, the function should set the <var>errorMessage</var> member variable of the FormField instance.
</dl>

<P>
<dl><dt><b><a name="l2h-35"><tt class="function">function: setFieldErrorMessage</tt></a></b>(<var>fieldName, errorMessage</var>)
<dd>
Sets the <var>errorMessage</var> member variable of the FormField instance whose name is <var>fieldName</var>.
</dl>

<P>
<dl><dt><b><a name="l2h-36"><tt class="function">function: getFieldOptionList</tt></a></b>(<var>fieldName</var>)
<dd>
Returns the <var>optionList</var> member variable of the FormField instance whose name is <var>fieldName</var>.
</dl>

<P>
<dl><dt><b><a name="l2h-37"><tt class="function">function: getFieldDefaultValue</tt></a></b>(<var>fieldName</var>)
<dd>
Returns the <var>defaultValue</var> member variable of the FormField instance whose name is <var>fieldName</var>.
</dl>

<P>
<dl><dt><b><a name="l2h-38"><tt class="function">function: setFieldDefaultValue</tt></a></b>(<var>fieldName, defaultValue</var>)
<dd>
Sets the <var>defaultValue</var> member variable of the FormField instance whose name is <var>fieldName</var>.
</dl>

<P>
<dl><dt><b><a name="l2h-39"><tt class="function">function: getFieldNameList</tt></a></b>(<var>exceptList=[]</var>)
<dd>
Returns the list of field names, based on the <var>fieldList</var> member variable. Names that are in <var>exceptList</var> are omitted.
</dl>

<P>
<dl><dt><b><a name="l2h-40"><tt class="function">function: validateForm</tt></a></b>()
<dd>
This function checks if the data that the user entered is correct or not. It returns 1 if it is, 0 otherwise.
</dl>

<P>
<dl><dt><b><a name="l2h-41"><tt class="function">view: postForm</tt></a></b>(<var>**kw</var>)
<dd>
This view is automatically called when the user submits the form. You should overwrite this view and add your own
code to handle the form data. Typical code for this view looks like this:
<div class="verbatim"><pre>
def postForm(self, **kw):
    if self.validateForm():
        # Yes, the data is correct
        # Do what you want here
        pass
    else:
        # No, the data is incorrect
        # Redisplay the form and tell the user to fix the errors:
        return "&lt;html&gt;&lt;body&gt;&lt;font color=red&gt;Fill out missing fields&lt;/font&gt;"+self.formView(1)+"&lt;/body&gt;&lt;/html&gt;"
</pre></div>
</dl>

<P>

<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node19.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A HREF="node16.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A HREF="node21.html"><img src="../icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Standard Library Reference</td>
<td><A href="contents.html"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node19.html">1.5.2.3 DefaultFormMask</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node16.html">1.5.2 Module</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node21.html">1.5.3 Writing a form</A>
<hr>
<span class="release-info">Release 0.10, documentation updated on 19 March 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>