Previous Next blank.gif blank.gif

Module StickyForm - StickyForm -- state maintaining HTML forms


SYNOPSIS

# Classes
class FormState(UserDict)
class StickyForm(Form)
# Functions
def compare_f2f(f1, f2)
def compare_s2f(s, f2)
def dump(data, filename)
def escape(text, replace=string.replace)
def imgsize(path)
def load(filename)
def markup_re(text, rex=None, marker=None, collapse=0)
def mpath(path)
def overlay_values(obj, dict)
def relpath(path1, path2)
# Variables
string CONTYPE = 'Content-Type: text/html\0 ...
string DOCTYPE = '<!DOCTYPE HTML PUBLIC "-/ ...
int I_am_a_list = 1
string __file__ = '/usr/local/lib/python1.5/ ...
string __version__ = '1.0.1'

DESCRIPTION

Intended to work with HTMLgen.

What is StickyForm?

It is a class which works with HTMLgen to provide state maintaining forms. Forms can load and save their state to and from files. This persistent state is what makes them sticky .

Why would I want to use it?

The same reason you'd want to use CGI.pm ;) Actually there are many CGI tasks which benefit from forms which can remember their settings. For example, in a hypothetical CGI program, a user could set their preferences with a form, and later return to the form to modify or review them.

How do I use it?

Simply create forms the same way you normally would with HTMLgen, only use the StickyForm class instead of the Form class.

StickyForm works like a Form with the addition of a state attribute, a save method and a restore method.

state
is a FormState instance which holds the default values for all form elements.
save
tells the FormState instance to save itself to a file.
restore
tells the FormState instance to restore itself from a file.

So how do I set a form's state?

You can set a form's state when you create it, and you can always change the state later by assigning something else to the form's state attribute.

There are three ways to indicate a StickyForm's state upon initialization:

filename
this loads the state of the form from a file
FieldStorage
this sets the state of the form from the information in the FieldStorage
FormState
this sets the state to the FormState instance

For each method here are some examples:

        form=StickyForm(state="/tmp/form.txt")
        cgi_results=cgi.FieldStorage()
        form=StickyForm(state=cgi_results)
        fs=FormState()
        form=StickyForm(state=fs)

What is the FormState class?

This is a simple dictionary which StickyForm uses to store its state information. A FormState instance can be intitalized with a FieldStorage instance, to create a form state which reflects the form data in the FieldStorage instance. This just means turning a slightly complex FieldStorage into a simple dictionary.

How is the form's state saved?

It is pickled to a file.

Does StickyForm work with Bobo or DocumentTemplate?

Yes, see the StickyForm page.

SEE ALSO

UserDict
UserList
cPickle
copy
os
re
string
time


Previous Next blank.gif blank.gif
Buzz.gif

Copyright © Amos Latteier
All Rights Reserved
Comments to author: amos@aracnet.com
Generated: Tue Apr 20, 1999