captcha validation is working now.

svn path=/plone.formwidget.captcha/trunk/; revision=28638
This commit is contained in:
Timo Stollenwerk 2009-08-10 14:25:10 +00:00
parent 4ea190686c
commit 465467d2dc
1 changed files with 11 additions and 1 deletions

View File

@ -1,9 +1,12 @@
from Acquisition import aq_inner
from zope import interface
from z3c.form import form, field, button
from zope import schema
from zope.component import getMultiAdapter
from z3c.form import form, field, button
from plone.z3cform.layout import wrap_form
from plone.formwidget.captcha.widget import CaptchaFieldWidget
class ICaptchaForm(interface.Interface):
captcha = schema.TextLine(title=u"Captcha",
description=u"",
@ -22,6 +25,13 @@ class BaseForm(form.Form):
@button.buttonAndHandler(u'Save')
def handleApply(self, action):
data, errors = self.extractData()
if data.has_key('captcha'):
# Verify the user input against the captcha
captcha = getMultiAdapter((aq_inner(self.context), self.request), name='captcha')
if captcha.verify(data['captcha']):
print 'Captcha validation passed.'
else:
print 'The code you entered was wrong, please enter the new one.'
return
CaptchaForm = wrap_form(BaseForm)