ZF-8485: Zend_Form_Element_Captcha always fails if rendered piecemeal

Issue Type: Bug Created: 2009-12-06T23:09:41.000+0000 Last Updated: 2012-11-20T21:38:11.000+0000 Status: Open Fix version(s): Reporter: Mon Zafra (monzee) Assignee: None Tags: - Zend_Form

Related issues: - ZF-9268

Attachments: - Captcha.diff


Related to [ZF-7404]. The reason my proposed fix was rather round-about was so that it would also cover the captcha form element. It still doesn't work, however. Before this, it isn't really possible to break apart and render separately a captcha element since important stuff is happening in render() which is skipped during __call(). Now it is possible to call renderCaptcha() and renderCaptcha_Word(), but they wouldn't ever match because the hidden element's value would be generated twice.

<pre class="highlight">

$form = new Zend_Form();
$form->addElement('captcha', 'captcha', array('captcha' => 'Dumb'))
     ->addElement('submit', 'submit');

if ($this->_request->isPost()) {
} else {
    echo $form->renderForm(false);
    echo $form->captcha->renderCaptcha();
    echo '<br></br>';
    echo $form->captcha->renderCaptcha_Word();
    echo $form->submit;
    echo '';

Action: enter the correct word Expected: true Actual: false

Unit test and proposed solution to follow.


Posted by Thomas Weidner (thomas) on 2009-12-07T00:16:12.000+0000

And where is the problem by calling...

<pre class="highlight">


Posted by Mon Zafra (monzee) on 2009-12-07T01:42:56.000+0000

An example is illustrated in the code above; i.e. if I wanted to insert arbitrary HTML between the captcha and the captcha input.

Posted by Mon Zafra (monzee) on 2009-12-07T04:09:18.000+0000

Attached patches to Zend_Form_Element, _Captcha and _Hash.

I added a pre-render hook to the base element class, which does nothing by default. What used to be in the render() methods of the Captcha and Hash classes are transferred into the hook. I also retconned my patch for [ZF-7404].

Posted by Mon Zafra (monzee) on 2009-12-07T04:09:50.000+0000

Attached unit tests

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.