Some of the information here may be outdated, please check the book instead
[edit]

Since version trunk 288 you can create dummy databases with SQLDB(None) and they can be used to generate form. Here is how.

Define the following helper function:

 def form_factory(*a): return SQLFORM(SQLDB(None).define_table(*a))

and now you can create a controller like the following

 def index():
     form=form_factory('myform',
            SQLField('name','string',requires=IS_NOT_EMPTY()),
            SQLField('age','integer',requires=IS_INT_IN_RANGE(0,150)),
            SQLField('image','upload'))
     if form.accepts(request.vars,session):
         response.flash='form accepted'
         ### do something with form.vars, perhaps redirect somewhere else
     elif form.errors:
         response.flash='errors in form'
     else:
         response.flash='please fill the form'
     return dict(form=form)

the form object, returned by form factory, behaves like a SQLFORM except that there is no insert because there is no DB. Notice that the image has been stored in a temporary file under uploads and its new name is in form.vars.image_newfilename

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.