HTML form pre-populating functionality or hints on building myown

Ian Bicking ianb at colorstudy.com
Thu Apr 17 21:42:36 CEST 2003


On Thu, 2003-04-17 at 06:32, Steve Holden wrote:
> I'd be happy to :-). See
> 
>     http://wwwsearch.sourceforge.net/ClientForm/
> 
> It's a very interesting module, and appears (from my own limited testing) to
> work well.
> 
> [...]
> 
> >From the documentation: """ClientForm is a Python module for handling HTML
> forms on the client side, useful for parsing HTML forms, filling them in and
> returning the completed forms to the server. It developed from a port of
> Gisle Aas' Perl module HTML::Form, from the libwww-perl library, but the
> interface is not the same"""

I think what the OP was talking about was different, meant to be used on
the server side.  Like you'd have a pseudo-template something like:

template = """
<form action="" method="POST">
<input type=text name=firstname value="">
<input type=text name=lastname value="">
<input type=submit value=register>
</form>
"""

Note that it doesn't look like a template at all, not even the most
minimal markup.  Then someone comes along and submits the form, but
forgets the firstname (though they remember the lastname).  You do
something like:

errors = False
if not form["firstname"]:
    write("Please enter your first name<br>")
    errors = True
if not form["lastname"]:
    write("Please enter your last name<br>")
    errors = True
if errors:
    write(subform(form, template))

And that subform function goes in, finds the <input...> tags, and fills
them in from the form dictionary, so that the user is presented with
their input and a chance to make corrections.

  Ian







More information about the Python-list mailing list