Skip to main content

Plone wtforms integration

Project description


collective.wtforms is plone integration with the WTForms form library.

Basic Complete Form Example

The basic form is constructed like so:

from wtforms import Form, TextField
from wtforms import validators
class MyForm(Form):
    one = TextField("Field One", [validators.required()])
    two = TextField("Field Two")
    three = TextField("Field Three")

from collective.wtforms.views import WTFormView
class MyFormView(WTFormView):
    formClass = MyForm
    buttons = ('Create', 'Cancel')

    def submit(self, button):
        if button == 'Create' and self.validate():
            # do fun stuff here
            self.context.value =

Then wire up the form with zcml:


You can also override the template used and then do:

<form tal:replace="structure view/renderForm" />

To render the form anywhere in your view.


You can specific which fields go with which fieldsets easily also:

class MyFormView(WTFormView):
    formClass = MyForm
    buttons = ('Create', 'Cancel')
    fieldsets = (
        ('Fieldset One', ('one', 'two')),
        ('Fieldset Two', ('three',))

    def submit(self, button):
        if button == 'Create' and self.validate():
            # do fun stuff here
            self.context.value =

This will render the form in the standard plone feildsets.

Control Panel

It’s also possible to easily construct a control panel form:

from collective.wtforms.views import WTFormControlPanelView
class MyFormView(WTFormControlPanelView):
    formClass = MyForm
    buttons = ('Save', 'Cancel')

    def submit(self, button):
        if button == 'Save' and self.validate():
            # do fun stuff here
            self.context.value =

WTFormView Class Properties

The WTForm class used. Required
The form label that shows up in the h1 tag
form description
The prefix of the form input name values. Defaults to wtform
The prefix of the button names. Defaults to form.actions.
A boolean that decides if it should wrap the fields in a fieldset. Defaults to True
Protect the form against csrf attacks. Defaults to True
An iterable of button names. Defaults to (‘Save’, ‘Cancel’)
An iterable of (fieldset name, (field names, …)). Defaults to empty
The instance of the WTForm form that is created on rendering the form.
Override this property to specify default values to populate the form with. This must return a dictionary.
Boolean if the form was submitted or not.
Method to render a specific field.
Method to render the entire form.
Check csrf protection and validates the form.

The method you must override to handle the form sumission and run validation. Return a value to override rendering the template(self.index()). For instance, if you do a redirect, there is no need to render the page also:

def submit(self, button):
    if button == 'Save' and self.validate():
        self.context.value =
        return 1
A method to mess with the form after it is created. This is what can be used to apply dynamic choices.


1.0a6 (2012-11-26)

  • handle spaces in button names [vangheem]

1.0a5 (2012-11-26)

  • handle unicode data [vangheem]
  • do not use and display dummy default form title and description
  • moved the field description after label, where commonly is
  • added locales directory, for being able to translate basic default buttons
  • provided italian translation
  • enabled the Plone form tabbing feature

1.0a4 (2012-08-29)

  • provide some bootstrap class hints

1.0a3 (2011-10-11)

  • fix issue where initial form data wouldn’t work in some instances.

1.0a2 (2011-10-06)

  • Fixed control panel template used.
  • add ability to easily mess with form after creation
  • add ability to provide initial data to form values

1.0a1 (2011-09-29)

  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date (30.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page