开发者

Zend Framework: Captcha problem

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="开发者_如何学Pythontext" name="captcha" id="captcha" value="eb3a592c8b1c7a71b0c7ce5179422be2">

Thanks in advance


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");


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?


You can try this:

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜