FormKit.Form
index
/usr/local/share/webware/FormKit/Form.py

# -*- coding: utf-8 -*-
## FormKit, Yet Another Webware Form processor
## Copyright (C) 2002, 2003 dAlchemy, Inc: www.dalchemy.com
##  
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
## or visit www.gnu.org

 
Modules
       
FormKit.BaseValidatorClasses
sys

 
Classes
       
Form

 
class Form
     Methods defined here:
__getattr__(self, fieldName)
convenience method that allows us to refer to fields of form
with .thing notation. Just returns the field class instance itself.
__init__(self, action='', method='post', validators=[], languageStandard='XHTML', encoding='utf-8', decoding_strict=1)
The Form constructor basically sets up a bunch of containers and switches.
definition is currently not used, but may be a way to have a form build itself later.
action is where the post goes (servlet, etc.) method is either get or post (defaults to post).
languageStandard sets the markup language the generated tags are expected to
conform to ( XHTML | HTML )
 
encoding is the kind of ascii (encoded unicode or other character set) that we're expecting...
assuming it's not just plain ascii already. For example, if you're expecting utf-8 from a form, set this to
utf-8 when you make a new Form() instance.
NB: To get this to work, your web server will have to send the html in the right encoding; if using apache,
use AddDefaultCharset NNNN (see http://httpd.apache.org/docs/mod/core.html#adddefaultcharset)
 
decoding_strict is a flag that tells the form to raise an exception when it gets confused decoding encoding strings...
if this is turned off, it simply quietly passes through perhaps bogus data, and you'll get garbage characters from your
fields, BUT it won't crash...
addField(self, field)
adds a field object into the form
addFormValidator(self, validator)
Adds a form validator
defaults(self)
returns all of the default values for all fields as a dictionary
dump(self)
returns a big string of the html required to SIMPLY paint the form for quick-and-dirty pages and for debugging
endTags(self)
returns the html that's required to end a form; basically a closing </form> tag, but 
including a hidden field to establish the form's name (for multiple forms)
error(self)
Form-wide error message access method (returns None if no error)
errors(self)
returns all of the error strings for all fields as a dictionary.
The key is the field name, the error is the value.
field(self, fieldName)
returns the asked for field class instance.
fields(self)
returns all of the fields as a list of field class instances; this list
preserves the order in which the fields were added
isSuccessful(self)
process(self, inputData)
inputData is a dictionary, where keys are the field names.
InputData is probably from post and querystring variables from a servlet,
but so long as it's a dictionary with keys that correspond to fields,
and values that fields can understand, it's kosher.
rawValues(self)
returns dict raw (un-validated, un-converted, etc.) values from the form
removeAllFields(self)
removes all fields in the form object
removeField(self, fieldName)
removes the field object called "fieldName" from the form; be careful with this method!
reset(self)
resets form to empty field values, clears errors, clears defaults, sets some flags back to off
seed(self, data={})
seed sends values (defaults) to the fields() field classes. data is a dictionary,
with the keys being the names of the field class instances. These values are NOT validated
or converted (but will be after they go through a submit-query and the resulting .process()).
 
Multiple calls to this method are allowed, and encouraged. If a second (or any subsequent)
call sends the same key as a previous call, it will stomp the values (as expected).
 
SPECIAL NOTE! It may be obvious, but empty strings DO stomp former values. This is good;
empty strings from a database SHOULD stomp "real" data from querystring or whatever.
 
'None' values DO NOT stomp previous values (as dictated by class Field )
setAction(self, target)
changes the form action (URL)
setDOMID(self, string='')
For setting a DOM id (no internal consequences other than the id='<string>' appears in the form start tag)
setEncoding(self, encoding='utf-8')
sets the encoding type for anticipated data (see __init__ docstrings)
setMethod(self, method)
set the post method: get or post
setTabOrder(self, order=None)
sets the tab order of the fields (using the tabindex parameter to html tags). Default is
to set them in the order that they were added to the form; alternatively, pass in a list of integers
that is the same length as the number of fields, or simply poke at each field with field.setTabIndex()
startTags(self)
returns the html that's required to start a form; basically an opening <form> tag with attributes
tag(self, fieldName)
returns the html <input> tag string of the asked-for field class instance.
value(self, fieldName)
returns the VALUE of the specified field class instance.
values(self)
returns all of the values for all fields as a dictionary

 
Data
        DEFAULT_ENCODING = 'utf-8'