I'm using captcha in my zend_form.
$captcha_element = new Zend_Form_Element_Captcha(
'captcha',
array('label' => 'Write the chars to the field',
'captcha' => array(
'captcha' => 'Image',
'wordLen' => 6,
'timeout' => 300,
'font' => DOC_ROOT . '/data/fonts/Vera.ttf',
'imgDir' => $imagedir,
'imgUrl' => $umageurl
)
)
);
This generates:
<dt id="captcha-input-label">
<label for="captcha-input" class="required">Write the chars to the field</label>
</dt>
<dd id="captcha-element">
<img width="200" height="50" alt="" src="http://sitename.com/captcha/09dd951939c6cdf7fa28f2b7d322ea95.png">
<input type="hidden" name="captcha[id]" value="09dd951939c6cdf7fa28f2b7d322ea95" id="captcha-id">
<input type="text" name="captcha[input]" id="captcha-input" value="">
</dd>
However. - I need following instead (captcha elements are wrapped into some tags individually):
<dt id="captcha-input-label">
<label for="captcha-input" class="required">Write the chars to the field</label>
</dt>
<dd id="captcha-element">
<div><span>
<input type="text" name="captcha[input]" id="captcha-input" value="">
</span></div>
<div><span>
<img width="200" height="50" alt="" src="http://sitename.com/captcha/09dd951939c6cdf7fa28f2b7d322ea95.png">
<input type="hidden" name="captcha[id]" value="09dd951939c6cdf7fa28f2b7d322ea95" id="captcha-id">
</span></div>
</dd>
I can't figure out how would I do this. Can I accomplish this by using some custom decorators? or woud that involve custom captcha ?
It was a bit tricky, but I prepared a custom Captcha element. I also needed to prepare custom Captcha decorator. In both cases I needed to override default render methods in both
Zend_Form_Element_Captcha
andZend_Form_Decorator_Captcha
. I also eliminatedZend_Form_Decorator_Captcha_Word
since I incorporated its functionality directly intoMy_Form_Decorator_Captcha
. There were two reasons for this. The first one is that order of form elements was changed, i.e. from default img, input hidden, input text into input text, img, input hidden. The second reason is that div and span tags needed to be added.Hopefully, they will be helpful:
My_Form_Element_Captcha:
My_Form_Decorator_Captcha: