source: products/quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/README.txt @ 2810

Last change on this file since 2810 was 2808, checked in by mylan, 14 years ago

#195: fixed grammar in README doctest

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1============================
2 quintagroup.formlib.captcha
3============================
4
5This package allows to add captcha to zope.formlib form.
6As a result such forms are prevented from automatic submit.
7
8 *example.py* module provides example of usage the *Captcha*
9 field with formlib form.
10
11What you have to do
12-------------------
13
141. You should add a *Captcha* field to your schema:
15
16  >>> from zope.interface import Interface
17  >>> from quintagroup.formlib.captcha import Captcha
18  >>> class ICaptchaFormlibFormSchema(Interface):
19  ...     # ... your schema definition
20  ...     captcha = Captcha(title=u'Type the code')
21
222. If your form define Schema adapter (ICaptchaFormlibFormSchema
23adapter in our case), just add *captcha* property.
24
25  >>> from zope.component import adapts
26  >>> from zope.interface import implements
27  >>> class CaptchaFormlibFormAdapter(object):
28  ...     adapts(Interface)
29  ...     implements(ICaptchaFormlibFormSchema)
30  ...     # ... your adapter code
31  ...     captcha = None
32 
33And away we go.
34
35In tests/tests.zcml we have registered a adapter and page view for test form,
36named @@formlib-captcha-form.
37
38Get browser object .
39   
40    >>> from Products.Five.testbrowser import Browser
41    >>> from Products.PloneTestCase import PloneTestCase as ptc
42    >>> user, pwd = ptc.default_user, ptc.default_password
43    >>> browser = Browser()
44
45Now check if captcha presented on the mentioned form.
46
47    >>> browser.open(self.portal.absolute_url() + '/@@formlib-captcha-form')
48    >>> open("/tmp/test.html", 'w').write(browser.contents)
49    >>> "Type the code" in browser.contents
50    True
51
52
53Now try to submit form with wrong captcha key. Error status message will
54be shown.
55
56    >>> browser.open(self.portal.absolute_url() + '/@@formlib-captcha-form')
57    >>> browser.getControl(name='form.captcha').value = "wrong captcha"
58    >>> browser.getControl(name='form..hashkey').value = self.hashkey
59    >>> browser.getControl(name="form.actions.save").click()
60    >>> "Type the code" in browser.contents
61    True
62    >>> "Please re-enter validation code." in browser.contents
63    True
64
65And now submit form with correct captcha key.
66
67    >>> browser.open(self.portal.absolute_url() + '/@@formlib-captcha-form')
68    >>> browser.getControl(name='form.captcha').value = self.captcha_word
69    >>> browser.getControl(name='form..hashkey').value = self.hashkey
70    >>> browser.getControl(name="form.actions.save").click()
71    >>> "Please re-enter validation code." in browser.contents
72    False
73
74No error shown.
Note: See TracBrowser for help on using the repository browser.