HTML_QuickForm2_Captcha: How to handle validation

From: Date: Thu, 20 May 2010 07:19:42 +0000
Subject: HTML_QuickForm2_Captcha: How to handle validation
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-53484@lists.php.net to get a copy of this message
Hi all, I'm underway implementing the captcha element for QuickForm2. The code is available on github [1]. I started looking at the QF1 captcha element, and it does things a bit different. One of the bigger differences are captcha validation handling. The QF1 captcha requires you to add a rule "CAPTCHA" that takes care of validating it. My QF2 Captcha element however does implement that in the validate() method, without requiring the explicit addition of a rule. In my eyes, this is more developer friendly since he does not have to care about adding the rule himself, and captchas are to be solved - I can't think of a use case that shows a captcha and does not require it to be solved. On the other hand, my way of doing it also means that the error message needs to be set as a element option, and not, as the developer is used to, as a normal rule parameter. The third hand is that the element needs more texts, i.e. the message when the captcha has been solved but the rest of the form is not valid yet. This makes it necessary to have more element options in my opinion. In the end, it's more consistent to set every message as element option. QF1 captcha code: ----------------- $captcha_question =& $form->addElement('CAPTCHA_Equation', 'captcha_question', 'Can you resolve this?', $options); $captcha_answer =& $form->addElement('text', 'captcha', 'Enter the answer'); $form->addRule('captcha', 'What you entered didn\'t match the equation', 'CAPTCHA', $captcha_question); QF2 captcha code: ----------------- $form->addElement( 'captcha', 'captchaelem', array( 'captchaSolved' => 'The captcha has been solved already', 'captchaSolutionWrong' => 'The captcha solution is wrong', ) ); [1] http://github.com/cweiske/HTML_QuickForm2_Captcha -- Regards/Mit freundlichen Grüßen Christian Weiske -=≡ Geeking around in the name of science since 1982 ≡=-

Attachment: [application/pgp-signature] signature.asc
« previous php.pear.dev (#53484) next »