Zend 框架:验证码问题

发布于 2024-11-26 00:23:09 字数 1208 浏览 1 评论 0原文

我使用以下代码生成验证码:

$captcha = $this->createElement('captcha', 'captcha',
    array('required' => true,
    'captcha' => array('captcha' => 'Image',
    'font' => 'resource/fonts/arial.ttf',
    'fontSize' => '24',
    'wordLen' => '5',
    'height' => '50',
    'width' => '150',
    'imgDir' => 'resource/captcha',
    'imgUrl' => 'resource/captcha',
    'gcFreq'=>'10',    
    'dotNoiseLevel' => '10',
    'lineNoiseLevel' => '2')));

    $captcha->setLabel('Captcha');

生成以下代码:

<label for="captcha-input" class="login_label required">Captcha</label>
<img width="150" height="50" alt="" src="captcha/eb3a592c8b1c7a71b0c7ce5179422be2.png" />
<input type="hidden" name="captcha[id]" value="eb3a592c8b1c7a71b0c7ce5179422be2" id="captcha-id">
<input type="text" name="captcha[input]" id="captcha-input" value="">
<input type="text" name="captcha" id="captcha" value="eb3a592c8b1c7a71b0c7ce5179422be2">

有人可以指导我如何删除额外的输入文本字段,例如

<input type="text" name="captcha" id="captcha" value="eb3a592c8b1c7a71b0c7ce5179422be2">

提前致谢

Iam using following code to generate CAPTCHA :

$captcha = $this->createElement('captcha', 'captcha',
    array('required' => true,
    'captcha' => array('captcha' => 'Image',
    'font' => 'resource/fonts/arial.ttf',
    'fontSize' => '24',
    'wordLen' => '5',
    'height' => '50',
    'width' => '150',
    'imgDir' => 'resource/captcha',
    'imgUrl' => 'resource/captcha',
    'gcFreq'=>'10',    
    'dotNoiseLevel' => '10',
    'lineNoiseLevel' => '2')));

    $captcha->setLabel('Captcha');

Following code is generated:

<label for="captcha-input" class="login_label required">Captcha</label>
<img width="150" height="50" alt="" src="captcha/eb3a592c8b1c7a71b0c7ce5179422be2.png" />
<input type="hidden" name="captcha[id]" value="eb3a592c8b1c7a71b0c7ce5179422be2" id="captcha-id">
<input type="text" name="captcha[input]" id="captcha-input" value="">
<input type="text" name="captcha" id="captcha" value="eb3a592c8b1c7a71b0c7ce5179422be2">

Can someone guide me how can I remove extra input text fields like

<input type="text" name="captcha" id="captcha" value="eb3a592c8b1c7a71b0c7ce5179422be2">

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心凉 2024-12-03 00:23:09

启用 ElementsDecorators 后执行此操作非常重要

$this->getElement('captcha')->removeDecorator("viewhelper");

(它首先设置 ViewHelper - 不要删除它,无论如何它都是必需的)

对我来说,它看起来像这样:

$this->setElementDecorators(array(
    'ViewHelper',
    'Errors',
    array(array('data' => 'HtmlTag'), array('tag' => 'td')),
    array('Label', array('tag' => 'td')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));

$this->getElement('captcha')->removeDecorator("viewhelper");

It's important to do the

$this->getElement('captcha')->removeDecorator("viewhelper");

after you have enabled the ElementsDecorators (which sets the ViewHelper in the first place - don't delete this, it's required anyway)

For me it looks like this:

$this->setElementDecorators(array(
    'ViewHelper',
    'Errors',
    array(array('data' => 'HtmlTag'), array('tag' => 'td')),
    array('Label', array('tag' => 'td')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));

$this->getElement('captcha')->removeDecorator("viewhelper");
半岛未凉 2024-12-03 00:23:09

该输入不是“额外的”——而是必不可少的。

验证验证码经过验证后,该字段的值将用于查找验证码的正确解决方案,然后将其与用户的输入进行比较。

如果没有该字段,您的验证码将会被破坏。

您为什么首先要删除它?

That input is not "extra" - it's essential.

When the CAPTCHA is validated, the value of that field is used to look up the correct solution to the CAPTCHA, which is then compared against the user's input.

Without that field, your CAPTCHA will break.

Why would you want to remove it in the first place?

俯瞰星空 2024-12-03 00:23:09

你可以试试这个:

$this->getElement('captcha')->removeDecorator("viewhelper");

You can try this:

$this->getElement('captcha')->removeDecorator("viewhelper");
不疑不惑不回忆 2024-12-03 00:23:09

我也有同样的问题。删除“ViewHelper”装饰器,验证码将正确呈现。

I had the same problem. Remove the "ViewHelper" decorator and the captcha will render properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文