Zope-like html-forms and required, disappearing values serverside in plain python

Ian Bicking ianb at colorstudy.com
Wed Jan 29 06:00:28 EST 2003


On Wed, 2003-01-29 at 04:34, Thomas Weholt wrote:
> I'm trying to implement something similar to Zopes html-forms:
> 
> <form ....>
>   <input type="text" name="name:string:required">
>   <input type="text" name="age:int">
>   ...
> </form>

This Zope technique is lame.  You shouldn't put validation information
into the form like this, you should keep it on the server side where
it's safe and can actually be trusted.  

I'd describe the form in the form handler.  (Well, I wrote FunFormKit
(.sf.net), so I went a lot further than that)

But even if you want something simple, putting that information in your
script should be easy, like:

def d(**kw): return kw
formRestrictions = d(name=d(type=string, required=1),
                     age=d(type=int))

Or something like that.  Or if I was to translate form submissions into
function/method calls, I'd use the signature, like:

def form(self, name, ageInt=None):
    ...

name is required since there's no default value, age is an integer
because it ends in Int.  Or you could put the type information into the
docstring or a function property (like form.inputTypes={"age": int}).

-- 
Ian Bicking           Colorstudy Web Development
ianb at colorstudy.com   http://www.colorstudy.com
PGP: gpg --keyserver pgp.mit.edu --recv-keys 0x9B9E28B7
4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241






More information about the Python-list mailing list