wiki:quintagroup.z3cform.captcha

quintagroup.z3cform.captcha

Introduction

quintagroup.z3cform.captcha allows adding captcha to z3c.form. As a result such forms are prevented from automatic submit. Captcha field for z3cform is based on quintagroup.captcha.core package.

Installation

Add quintagroup.z3cform.captcha to your buildout eggs and zcml area:

    [buildout]
    ...
    eggs =
        ...
        quintagroup.z3cform.captcha
	
    [instance]
    recipe = plone.recipe.zope2instance
    ...
    zcml =
        quintagroup.z3cform.captcha

Re-run your buildout, e.g. with the following command:

    $ ./bin/buildout

This package does not require installation in Plone.

Captchas in a z3c form

Using quintagroup.z3cform.captcha in a z3c.form form is simple. Just add a Captcha field to your schema, use CaptchaWidgetFactory widget factory for this field and away you go:

    >>> from zope.interface import Interface
    >>> from z3c.form import form, field
    >>> from quintagroup.z3cform.captcha import Captcha
    >>> from quintagroup.z3cform.captcha import CaptchaWidgetFactory

Now define form schema with Captch field

    >>> class ICaptchaSchema(Interface):
    ...     captcha = Captcha(
    ...         title=_(u'Type the code'),
    ...         description=_(u'Type the code from the picture shown below.'))

And set proper widget factory for the captcha field

    >>>  class CaptchaForm(form.Form):
    ...      fields = field.Fields(ICaptchaSchema)
    ...      fields['captcha'].widgetFactory = CaptchaWidgetFactory

and z3c.form will take care of the rest. The widget associated with this field will render the captcha and verify the use input automatically.

Supported Plone Versions

quintagroup.z3cform.captcha was tested with Plone 3.0.6, 3.1.7, 3.2.3, 3.3.4.

Last modified 15 years ago Last modified on May 4, 2010 12:16:41 PM