Forms and validators
There are four distinct ways to build forms in web2py:
FORM
provides a low-level implementation in terms of HTML helpers. AFORM
object can be serialized into HTML and is aware of the fields it contains. AFORM
object knows how to validate submitted form values.SQLFORM
provides a high-level API for building create, update and delete forms from an existing database table.SQLFORM.factory
is an abstraction layer on top ofSQLFORM
in order to take advantage of the form generation features even if there is no database present. It generates a form very similar toSQLFORM
from the description of a table but without the need to create the database table.CRUD
methods. These are functionally equivalent to SQLFORM and are based on SQLFORM, but provide a more compact notation;CRUD
is now deprecated in favor ofSQLFORM.grid()
andSQLFORM.smartgrid()
.
All these forms are self-aware and, if the input does not pass validation, they can modify themselves and add error messages. The forms can be queried for the validated variables and for error messages that have been generated by validation.
Arbitrary HTML code can be inserted into or extracted from the form using helpers.
FORM
and SQLFORM
are helpers and they can be manipulated in a similar way as the DIV
. For example you can set a form style:
form = SQLFORM(..)
form['_style']='border:1px solid black'