| 13 | == Captchas in a z3c form == |
| 14 | |
| 15 | 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: |
| 16 | |
| 17 | {{{ |
| 18 | >>> from zope.interface import Interface |
| 19 | >>> from z3c.form import form, field |
| 20 | >>> from quintagroup.z3cform.captcha import Captcha |
| 21 | >>> from quintagroup.z3cform.captcha import CaptchaWidgetFactory |
| 22 | }}} |
| 23 | |
| 24 | Now define form schema with Captch field |
| 25 | |
| 26 | {{{ |
| 27 | >>> class ICaptchaSchema(Interface): |
| 28 | ... captcha = Captcha( |
| 29 | ... title=_(u'Type the code'), |
| 30 | ... description=_(u'Type the code from the picture shown below.')) |
| 31 | }}} |
| 32 | |
| 33 | And set proper widget factory for the captcha field |
| 34 | |
| 35 | {{{ |
| 36 | >>> class CaptchaForm(form.Form): |
| 37 | ... fields = field.Fields(ICaptchaSchema) |
| 38 | ... fields['captcha'].widgetFactory = CaptchaWidgetFactory |
| 39 | }}} |
| 40 | |
| 41 | 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. |
| 42 | |
| 43 | |