zend形式验证码问题

时间:2011-04-21 11:45:11

标签: php zend-framework zend-form zend-decorators

我正在以zend形式使用zend验证码。它工作正常,但是当它创建时它会生成这个代码:

<img width="80" height="30" alt="Allindia captcha" src="/allindiazend/public/images/captcha/4ae305b05406c9d8b06a19ea7ff2c9d9.png"/><br/>
<input type="hidden" name="captcha[id]" value="4ae305b05406c9d8b06a19ea7ff2c9d9" title="Security Check." id="captchas" />
<input type="text" name="captcha[input]" id="captchas" value="" title="Security Check." />

由于此<br/>,文本框位于img下方。我不想在生成的代码中使用这个'br'标记。

这是我的验证码:

$captcha= new Zend_Form_Element_Captcha('captcha', array(
                'id'=>'captchas',
                'title'=>'Security Check.',
                'captcha' => array(
                'captcha' => 'Image',
                'required' => true,
                'font'=>'arial.ttf',
                'wordlen'=>'4',
                'width'=>'80',
                'height'=>'30',
                'ImgAlign'=>'left',
                'imgdir'=>'public/images/captcha',
                'DotNoiseLevel'=>'0',
                'LineNoiseLevel'=>'0', 
                'Expiration'=>'1000',
                'fontsize'=>'16',
                'gcFreq'=>'10',
                'ImgAlt'=>'Allindia captcha',
                'imgurl'=>'/allindiazend/public/images/captcha',
                'GcFreq'=>'5'
                )));

任何人都可以帮助我。

2 个答案:

答案 0 :(得分:3)

这不需要对captcha本身的配置做任何事情,而是使用form-element。我想这个<br />被添加到Zend_Form_Element_Captcha的任何默认装饰器中。看看哪些装饰器附加到表单上,如下所示:

echo '<pre>'; print_r($captcha->getDecorators()); echo '</pre>'; exit;

你会看到所有装饰者。尝试逐步删除所有装饰器,以查看哪些装饰器生成<br />。完全删除它或者如果有必要用你自己的装饰器覆盖它,省略<br />

答案 1 :(得分:0)

我通常做这样的事情

foreach($this->getElements() as $element) {
    $element->removeDecorator('HtmlTag')
        ->removeDecorator('Label')
        ->addDecorator('Label');
}

删除默认的装饰器并创建空白的

相关问题