I've activated AJAX Forms on user registration form, where I also has CAPTCHA 6.x-1.0-rc2. I'm using Drupal 6.6.

When I tested the form, I made a mistake in username and left a field empty that should be filled out, to see if everything was working as expected. It worked very well, and I was quite happy there for a moment. Until I corrected my "mistakes", and submitted the form again. Then I got this:

"Invalid CAPTCHA token."

I then checked to see if the captcha was working, if I filled out the form correctly, and it worked like a charm. Tried to make a new mistake, and thereby activated the AJAX form module, and got the samme message: "Invalid CAPTCHA token."

I assume it must be something in this module causing this?

Any suggestions?

I really would like to use this module if possible, because it seems so userfriendly with this help on the forms without reloading pages :)

Comments

brendoncrawford’s picture

Version: 6.x-1.3 » 6.x-1.x-dev
Assigned: Unassigned » brendoncrawford
Category: bug » feature
Priority: Normal » Minor

Thanks for your feedback. I will look into getting the module to work with captcha forms. Check back here for updates.

soelver’s picture

I will :)
Thank you for looking into that.

Just a small question: Is the 6.x-1.x-dev and the 6.x-1.3 versions the same?
I've got the 6.x-1.3 version, but you've changed it.

I'm trying to learn how this issue-stuff works, so I'd be happy to know, if I'm doing something wrong, so I could do it right in the future :)

brendoncrawford’s picture

Version: 6.x-1.x-dev » 6.x-1.3

Changed it back. They are very slightly different.
When filing bugs, try your best to always test the latest dev version, in the case that your bug was addressed since the major release.

In this particular case, you did it right though.

brendoncrawford’s picture

Version: 6.x-1.3 » 6.x-1.x-dev
Status: Active » Fixed

Soelver,

This has been fixed for captcha-6.x-1.0-rc2 in ajax-6.x-1.x-dev. There is now a "patches/captcha" directory which contains a set of patches that you must apply in order for Ajax forms to work with Captcha.

If interested, you can also see that I have submitted these patches to the module author here: http://drupal.org/node/334377. Perhaps you can vote these up so he will commit them to Captcha core.

brendoncrawford’s picture

Soelver,

I forgot to mention that you will need to wait up to 12 hours for the 6.x-1.x-dev package to update.

soelver’s picture

I have no clue, how to apply a patch, but I will read up on that, and see if I can make it work myself. If not, I have a friend with more technical skills than me, who probably can help me along.

How do I vote the patches up?
By letting them know, that it's needed?

Sorry for my helpless questions :)

I hope it works.
I will try it out tomorrow, when I can download the newest dev, and let you know how it goes.

Thank you for the time already spent on this.

brendoncrawford’s picture

You can read more about applying patches here: http://drupal.org/node/60108.

To vote the patch up, just leave a comment and say that you support the patch and want to see it in the core module.

Thanks

arski’s picture

Hi,

I've tried to apply your patch on both the latest dev and the latest stable release of CAPTCHA 6.x and both don't work. I still get exactly the same error as described above. I've tried disabling and reenabling both products, that didn't help either. Is there some further step I need to do after having applied the patch?

Thanks,

Martin

soelver’s picture

Good that someone knows how to try it out. I'm still waiting for help from a friend :)

arski’s picture

soelver, you can pretty much apply the patch manually.. there are 3 patch files with names corresponding to real files in the captcha/ module folder..

open the .patch file, it will have some lines with a "+" in them.. these lines you need to add to your captcha.module file.. to know the correct position, you can either check the context (lines before the "+"-marked lines) or see line number specified at the beginning of each block around the "+"-lines.. Oh and obviously the "-" lines are the ones you need to remove..

Now I've done that, but I suppose one needs to reload the module somehow or there is still something missing, coz it doesnt' fix the problem :(

brendoncrawford’s picture

Arski,

Did the patches apply correctly?
Did you try clearing the cache?
What is the exact version of Captcha that you are using?
Which type of Captcha are you using (image, math, text, etc)?
Did you enable the forms in the Ajax Forms Settings page?

brendoncrawford’s picture

Status: Fixed » Postponed (maintainer needs more info)
brendoncrawford’s picture

Changing status

arski’s picture

Hi, patches seem to have applied without any errors.

Tried clearing cache, reinstalling, pretty much everything, yes.

Using latest dev version of captcha, which, according to the site, should be "6.x-1.x-dev 2008-Nov-21"
but captcha.module says "// $Id: captcha.module,v 1.58.2.9 2008/08/30 01:20:18 soxofaan Exp $"

Also tried the latest stable release of captcha.

Did most test with the math captcha, but also tried others, same result.

Yes, enabled the forms (tried different forms as well).

My assumption is in the captcha_captcha function.. there the patch makes sure, that the same query is displayed over and over again.. but the "answer" is generated anew, isn't it? To test and confirm this I did the following:

1. click on submit without entering any captcha solution -> "captcha field is required" message
2. submit with correct solution -> "captcha wrong" message
3. keep trying to submit with the same results -> after some 20-30 clicks the solution was accepted, meaning that the module has accidentally generated a query with the same answer as in the first form.. meaning that the $answer is being recomputed, when it shouldn't.

Hope this helps,

Martin

soelver’s picture

I downloaded the AJAX Forms the day after message #4.
So I have:

CAPTCHA 6.x-1.0-rc2
AJAX Forms 6.x-1.x-dev (2008-Nov-09)

This was the two versions that I was supposed to use at the time you submitted the patches, so that should work in theory :)

I've now applied the patches manually as suggested in #10. I obviously don't know, if I've made a mistake, but tried to make a new account to see if Captcha was working properly alone, and it did :) So I assume I did it correct.

I then cleared my cache, backed up the site, ran php-update (just in case), and tried to leave the captchafield blank, as described above. Same message as before: "Captcha token invalid". Also tried submitting the form over and over again (actually 70 times, then I gave up).

I'm using math-questions for the Captcha field.

brendoncrawford’s picture

Status: Postponed (maintainer needs more info) » Active

Arski, Soelver,

The Captcha module has a lot of confusing stuff in it. I guess I will have to dig into that patch again. This may take a few weeks for me to finish to be honest, but I will get it fixed. If you guys want to dig in and try to fix it as well, I would be extremely appreciative.

For now, leaving this bug open.

arski’s picture

well.. I've found a fix that works.. however might not be perfect..

unset($_SESSION['captcha'][$form_id][$captcha_token]);

See that line unsets the solution from the session and the way AJAX loads the page, it doesn't go to pre_render to set it again.. (or set a new one as it would without ajax..).. so if you comment out that page, the ajaxified form works like a charm..

The comment before that lines says that it's made to prevent spammers sending a form request without actually posting.. but in a way this is what ajax is doing here, so.. any better ideas?

arski’s picture

One thing I would really love to have tho is the captcha ajax-removed when it's entered correctly.. one can't access the session from js, but one can check if one of the error fields is "captcha_content".. I was able to do that in your ajax code, but I couldn't really figure out how the elements are accessed and how it would be possible to make the captcha disappear :o

Hope you can help with this.. thanks a lot!

brendoncrawford’s picture

Arski,

I will look into that Session variable. Thanks.

brendoncrawford’s picture

Status: Active » Fixed

I have made some fixes to the captcha handling. The patches remain the same, but the module code has changed. As of now, captcha-6.x-1.0-rc2 on Drupal 6.6 with zzzz_ajax-6.x-1.4 seems to be working quite well.

Let me know if you are having any other problems.

Thanks

arski’s picture

Hi,

I see you made the CAPTCHA renew itself on every missing/wrong submission. Works like a charm.

However there is still one ugly "feature": if I submit the correct captcha but have an error somewhere else in the form, i.e. the form is displayed again, I also get the captcha field again with a new task.. it doesn't matter if I enter something in there or if it's correct now (since the setting on my site is to store a cookie once the user has submitted a captcha correct once), but this is really distracting and just not nice :)

Could you maybe take a look at some way of making the captcha field disappear altogether if the site is configured to not show it again if it has been submitted correctly once.

Thanks again for the patch!

Martin

brendoncrawford’s picture

Arski,

Could you open a new bug for this?

Thanks,
brendon

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

pulai001’s picture

dsfvdsfvdsgfdsgfdsgf