My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 4: Captcha is not compatible with formwizard
3 people starred this issue and may be notified of changes. Back to list
Status:  Accepted
Owner:  mbonetti

Sign in to add a comment
Reported by, Apr 5, 2009
What steps will reproduce the problem?
1. Create formwizard (from django.contrib)
2. Put captcha into one of the forms in this wizard
3. Captcha does not get validated

What is the expected output? What do you see instead?
I expect captcha to pass but it never happens

What version of the product are you using? On what operating system?
Version: 1.1 alpha 1 SVN-9975 latest django-simple-captcha from SVN

Please provide any additional information below.
FormWizard does validation twice (after form submission and after the last
step), but the record gets deleted after the 1st validation, so maybe its
possible to store validation result for reuse...

Apr 27, 2009
Project Member #1 mbonetti
I've never used the formwizard contrib, but will definitely give it a try and see how
I can fix DSC to work with it, though.

Status: Accepted
Owner: mbonetti
Labels: -Type-Defect Type-Enhancement
Apr 27, 2009
Actually I'm not sure if the problem is in captcha itself. I've filed a ticket - but the solution proposed is a work-around
and I haven't found how to combine "one-way" fields with formwizard. It looks like
conflicting requirements (revalidation in formwizard and single validation in captcha)
Apr 27, 2009
Project Member #3 mbonetti
A quick-fix would probably be to comment-out the store.delete() line on line 58 of, and configure a large-enough CAPTCHA_TIMEOUT period, so that the captcha
can be validated an unlimited numbed of times, during the validity period.

Apr 27, 2009
Of course, but I don't think it's the right way to do it...
Feb 2, 2011
My approach was to inherit my own FormWizard class from the one provided
in django.contrib.formtools.

My derived class implements its own __call__() method, which is basicaly cut'n'pasted
from django with small difference, see following patch:

--- /tmp/    2011-02-03 01:10:20.000000000 +0100
+++ /tmp/    2011-02-03 01:11:16.000000000 +0100
@@ -41,7 +41,7 @@
                 # must mean the validator relied on some other input, such as
                 # an external Web site.
                 for i, f in enumerate(final_form_list):
-                    if not f.is_valid() and not self.has_captcha_field(f):
+                    if not f.is_valid():
                         return self.render_revalidation_failure(request, i, f)
                 return self.done(request, final_form_list)

@@ -51,4 +51,3 @@
                 self.step = current_step = next_step

         return self.render(form, request, current_step)

the derived class also implements a static method has_captcha_field(),
which looks as follows:
    def has_captcha_field(form):
        for f in form.fields:
            if type(form[f].field) == type(CaptchaField()):
                return True
        return False

it works for me pretty well.

Apr 1, 2011
My workaround has been call "storage.delete()" at the method "__delete__" of the field class, this way the field can be cleaned more than once in the context of the same instance and not in multiple requests.
4.0 KB   View   Download
Sign in to add a comment

Powered by Google Project Hosting