The base class of all forms. To create a new form, simply derive it from Form:
class MyForm(Form):
my_string = String()
You can initialize the values in the form by passing a mapping or using keyword arguments. Both ways are equivalent:
my_form = MyForm({'my_string': 'some text'})
my_form = MyForm(my_string='some text'})
Then call Form.validate() to validate the data:
if my_form.validate({'my_string': 'What I write'}):
print 'Valid'
else:
print 'Invalid'
Set the fields’ values back to their initial values. This allows you to reuse forms:
>>> class MyForm(Form):
... my_string = field.String()
>>> my_form = MyForm(my_string='initial')
>>> my_form.my_string.data
'initial'
>>> my_form.validate({'my_string': 'something'})
True
>>> my_form.my_string.data
'something'
>>> my_form.reset()
>>> my_form.my_string.data
'initial'
Return True if the form is valid. A form is valid if there was no errors during the previous validation. This means that when a form is created it is automatically considered valid:
>>> class MyForm(Form):
... x = field.String(required=True)
>>> my = MyForm()
>>> my.valid()
True
>>> my.validate({})
False
>>> my.valid()
False
data must be a dictionnary-like object. Return True if the form is valid.