1

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

Simpanoz
  • 2,729
  • 10
  • 43
  • 64

4 Answers4

3

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");
Alex
  • 46
  • 2
0

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?

timdev
  • 61,857
  • 6
  • 82
  • 92
  • So what is the purpose of it? I think, only one input field should be visible. In my form, two input fields are visible, one is empty, and other is containing code. – Simpanoz Jul 23 '11 at 10:33
0

You can try this:

$this->getElement('captcha')->removeDecorator("viewhelper");
Regis
  • 142
  • 5
0

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

eroteev
  • 620
  • 1
  • 7
  • 17