Closed (fixed)
Project:
CAPTCHA
Version:
5.x-3.x-dev
Component:
Captcha API (captcha)
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Aug 2007 at 14:43 UTC
Updated:
8 Jan 2011 at 00:37 UTC
When a user types in an incorrect response into the Captcha challenge, with the 'preprocess' option, is it possible to pass the returned value (whether they previously answered incorrectly) to the 'generate' operation?
The reason I'm asking is so that reCAPTCHA could present the error in the challenge form itself instead of using form_set_error(). Like what you see when you enter an incorrect answer here.
Comments
Comment #1
soxofaan commentedAvoiding form_set_error() seems not a good idea, I think. If you don't use it during validation, Drupal won't know there is an error and will accept the submission.
Comment #2
robloachNot instead of, but in addition to form_set_error. That's beside the point though.... Is there a way to return the result of preprocess to the generate operation of hook_captcha?
Comment #3
soxofaan commentedDo you want the result of the preprocessing (which is the response to validate) or the result of the validation (which is 'success'/'failed')?
Do you want do it through the API? You could for example do some housekeeping of your own in $_SESSION.
Or do you want to put this in captcha.module independently from ReCAPTCHA?
It could make sense to provide the generate hook with information about the previous submission attempts (if any). The difficulty is that captchas are per form instance (identified by form_id and captcha_token). Captchas from subsequent form requests are unrelated and don't share information. Also the validation result (success/fail) is not saved in any way.
Comment #4
soxofaan commentedI tried some stuff and found out that with Drupal the form generation (and thus captcha generation) is done before validation of the (previously) submitted form. This is done because drupal needs the form structure before it can validate the submission. So during generation you can't now if validation of the previous post passed (unless you pull in the posted values and do some validation yourself)
I think it won't be easy (and at least very ugly) to do what you want to do.
Comment #5
robloachYeah, I tried some stuff out with $_SESSION and it wasn't doing it... What a pain...
One way of doing it would be using drupal_goto() along with $_SESSION, but that's horribly ugly. You have any ideas?
Comment #6
robloachI think passing what's returned from 'preprocess' to 'generate' would make the most sense. Then you could pass your own custom error flags and stuff.
I attempted doing it without modifying the API (even that wasn't possible), but then I realized that other Captchas might also benefit from having the extra parameter passed to the 'generate' operation.
Comment #7
soxofaan commentedMaking it possible through the API is a no go, I think. Like I previously explained, with Drupal there is no "clean" way possible for knowing during form generation if validation of the previous post was successful. I don't think it is a good idea to pollute the base captcha module with ugly/hackish code.
However, I had the following idea: with an additional pre_render procedure it should be possible to detect the error state (with form_get_errors()) and add some stuff to your form elements. The problem is that you have to set the #pre_render attribute at the toplevel of $form, so there is some API change needed.
Comment #8
robloachHaha, this could even lead to a multi-step captcha system for Captcha Pack..... They'd have to answer one question, hit submit, and then answer the second captcha question, in order to fully submit the form.
Comment #9
soxofaan commentedI wouldn't do that.
I guess most human users would find this annoying behavior. (I would).
CAPTCHAs are already experienced as an annoying hurdle, so I would try to keep the annoyance (for humans) to a minimum.
Comment #10
robloachIt was meant as a joke ;-) .
Comment #11
soxofaan commentedclosing old outdated issue