1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4
<title>4.6.1 FieldStorage class</title>
5
<META NAME="description" CONTENT="4.6.1 FieldStorage class">
6
<META NAME="keywords" CONTENT="modpython">
7
<META NAME="resource-type" CONTENT="document">
8
<META NAME="distribution" CONTENT="global">
9
<link rel="STYLESHEET" href="modpython.css">
10
<link rel="first" href="modpython.html">
11
<link rel="contents" href="contents.html" title="Contents">
12
<link rel="index" href="genindex.html" title="Index">
13
<LINK REL="next" href="pyapi-util-fstor-fld.html">
14
<LINK REL="previous" href="pyapi-util.html">
15
<LINK REL="up" href="pyapi-util.html">
16
<LINK REL="next" href="pyapi-util-fstor-fld.html">
19
<DIV CLASS="navigation">
20
<table align="center" width="100%" cellpadding="0" cellspacing="2">
22
<td><A href="pyapi-util.html"><img src="icons/previous.gif"
23
border="0" height="32"
24
alt="Previous Page" width="32"></A></td>
25
<td><A href="pyapi-util.html"><img src="icons/up.gif"
26
border="0" height="32"
27
alt="Up One Level" width="32"></A></td>
28
<td><A href="pyapi-util-fstor-fld.html"><img src="icons/next.gif"
29
border="0" height="32"
30
alt="Next Page" width="32"></A></td>
31
<td align="center" width="100%">Mod_python Manual</td>
32
<td><A href="contents.html"><img src="icons/contents.gif"
33
border="0" height="32"
34
alt="Contents" width="32"></A></td>
35
<td><img src="icons/blank.gif"
36
border="0" height="32"
37
alt="" width="32"></td>
38
<td><A href="genindex.html"><img src="icons/index.gif"
39
border="0" height="32"
40
alt="Index" width="32"></A></td>
42
<b class="navlabel">Previous:</b> <a class="sectref" href="pyapi-util.html">4.6 util - Miscellaneous</A>
43
<b class="navlabel">Up:</b> <a class="sectref" href="pyapi-util.html">4.6 util - Miscellaneous</A>
44
<b class="navlabel">Next:</b> <a class="sectref" href="pyapi-util-fstor-fld.html">4.6.2 Field class</A>
47
<!--End of Navigation Panel-->
49
<H2><A NAME="SECTION006610000000000000000"> </A>
51
4.6.1 FieldStorage class
55
Access to form data is provided via the <tt class="class">FieldStorage</tt>
56
class. This class is similar to the standard library module
57
<tt class="module">cgi</tt> <tt class="class">FieldStorage</tt>.
60
<dl><dt><b><span class="typelabel">class</span> <a name="l2h-169"><tt class="class">FieldStorage</tt></a></b>(<var>req</var><big>[</big><var>, keep_blank_values, strict_parsing</var><big>]</big>)
62
This class provides uniform access to HTML form data submitted by the
63
client. <var>req</var> is an instance of the mod_python request object.
66
The optional argument <var>keep_blank_values</var> is a flag indicating
67
whether blank values in URL encoded form data should be treated as
68
blank strings. The default is false, which means that blank values are
69
ignored as if they were not included.
72
The optional argument <var>strict_parsing</var> is not yet implemented.
75
During initialization, <tt class="class">FieldStorage</tt> class reads all of the
76
data provided by the client. Since all data provided by the client is
77
consumed at this point, there should be no more than one
78
<tt class="class">FieldStorage</tt> class instantiated per single request, nor should
79
you make any attempts to read client data before or after
80
instantiating a <tt class="class">FieldStorage</tt>.
83
The data read from the client is then parsed into separate fields and
84
packaged in <tt class="class">Field</tt> objects, one per field. For HTML form inputs
85
of type <code>file</code>, a temporary file is created that can later be
86
accessed via the <tt class="member">file</tt> attribute of a <tt class="class">Field</tt> object.
89
The <tt class="class">FieldStorage</tt> class has a mapping object interface, i.e. it
90
can be treated like a dictionary. When used as a mapping, the keys are
91
form input names, and the returned dictionary value can be:
96
<LI>An instance of <tt class="class">StringField</tt>, containing the form input
97
value. This is only when there is a single value corresponding to the
98
input name. <tt class="class">StringField</tt> is a subclass of <tt class="class">str</tt> which
99
provides the additional <tt class="member">value</tt> attribute for compatibility
100
with standard library <tt class="module">cgi</tt> module.
102
<LI>An instances of a <tt class="class">Field</tt> class, if the input is a file upload.
104
<LI>A list of <tt class="class">StringField</tt> and/or <tt class="class">Field</tt> objects. This is
105
when multiple values exist, such as for a <code><select></code> HTML form
112
<div class="note"><b class="label">Note:</b>
113
Unlike the standard library <tt class="module">cgi</tt> module
114
<tt class="class">FieldStorage</tt> class, a <tt class="class">Field</tt> object is returned
115
<i>only</i> when it is a file upload. In all other cases the
116
return is an instance of <tt class="class">StringField</tt>. This means that you
117
do not need to use the <tt class="member">.value</tt> attribute to access values
118
of fields in most cases.
122
In addition to standard mapping object methods, <tt class="class">FieldStorage</tt> objects
123
have the following attributes:
126
<dl><dt><b><a name="l2h-170"><tt class="member">list</tt></a></b>
128
This is a list of <tt class="class">Field</tt> objects, one for each input. Multiple
129
inputs with the same name will have multiple elements in this list.
133
<tt class="class">FieldStorage</tt> methods:
136
<dl><dt><b><a name="l2h-171"><tt class="method">getfirst</tt></a></b>(<var>name</var><big>[</big><var>, default</var><big>]</big>)
138
Always returns only one value associated with form field
139
<var>name</var>. If no such form field or value exists then the method
140
returns the value specified by the optional parameter
141
<var>default</var>. This parameter defaults to <code>None</code> if not
146
<dl><dt><b><a name="l2h-172"><tt class="method">getlist</tt></a></b>(<var>name</var>)
148
This method always returns a list of values associated with form
149
field <var>name</var>. The method returns an empty list if no such form
150
field or value exists for <var>name</var>. It returns a list consisting
151
of one item if only one such value exists.
159
<DIV CLASS="navigation">
161
<table align="center" width="100%" cellpadding="0" cellspacing="2">
163
<td><A href="pyapi-util.html"><img src="icons/previous.gif"
164
border="0" height="32"
165
alt="Previous Page" width="32"></A></td>
166
<td><A href="pyapi-util.html"><img src="icons/up.gif"
167
border="0" height="32"
168
alt="Up One Level" width="32"></A></td>
169
<td><A href="pyapi-util-fstor-fld.html"><img src="icons/next.gif"
170
border="0" height="32"
171
alt="Next Page" width="32"></A></td>
172
<td align="center" width="100%">Mod_python Manual</td>
173
<td><A href="contents.html"><img src="icons/contents.gif"
174
border="0" height="32"
175
alt="Contents" width="32"></A></td>
176
<td><img src="icons/blank.gif"
177
border="0" height="32"
178
alt="" width="32"></td>
179
<td><A href="genindex.html"><img src="icons/index.gif"
180
border="0" height="32"
181
alt="Index" width="32"></A></td>
183
<b class="navlabel">Previous:</b> <a class="sectref" href="pyapi-util.html">4.6 util - Miscellaneous</A>
184
<b class="navlabel">Up:</b> <a class="sectref" href="pyapi-util.html">4.6 util - Miscellaneous</A>
185
<b class="navlabel">Next:</b> <a class="sectref" href="pyapi-util-fstor-fld.html">4.6.2 Field class</A>
187
<span class="release-info">Release 3.1.3, documentation updated on February 17, 2004.</span>
189
<!--End of Navigation Panel-->