Rok Garbas: Complex Forms with z3c.form

published Oct 28, 2009, last modified Oct 29, 2009

By Rok Garbas, Slovenia

Rok Garbas talks about the z3c.form form framework. Everybody is talking about is, using it, so it is time you learn how to (ab)use it and step into the Plone future. Tricks and things you might want to hear again. I won't speak about the internal structure, or why you would want to use it, or compare it with other frameworks.

For code examples, see his talk once it is uploaded to the Plone Conference 2009 website.

On the form you can set ignoreContext and ignoreRequest to control whether the form displays any values and where it gets it from.

Don't forget to package="plone.app.z3c.form" /> in your zcml when you use z3c.form in Plone.

You can register zope vocabularies and use that in your forms.

You can change the form layout. For that you create a layout factory, inheriting from plone.z3cform.templates.ZopeTwoFormTemplateFactory.

You can define your own widgets, for example to combine three inputs into one field.

You can create a custom data converter. It converts from the field to the widget (e.g. split fullname field into first name and last name inputs in the widget) or the other way around.

Within the form normally the default widgets are used. If you want to use your own widgets, you need to override the widgetFactory for that field in the form definition.

You can create group forms, which can be compared to Archetypes forms with tabs. Inherit from z3c.form.group.GroupForm.

In form wizards you can combine steps, so you can link different forms. Use collective.z3cform.wizard.

For more information, see http://docs.zope.org/z3c.form and http://pypi.python.org/pypi/plone.app.z3cform

Read Rok Garbas blog.