Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Error Message for Captcha Element In Zend Framework 1.10

I am trying to set my own custom error message onto my Captcha but for some reason it is echoing twice.

Here is my captcha code:

$captcha = new Zend_Form_Element_Captcha(
  'captcha', // This is the name of the input field
  array('captcha' => array(
      // First the type...
      'captcha' => 'Image',
      // Length of the word...
      'wordLen' => 6,
      // Captcha timeout, 5 mins
      'timeout' => 300,
      // What font to use...
      'font' => 'images/captcha/font/arial.ttf',
      // URL to the images
      'imgUrl' => '/images/captcha',
      //alt tag to keep SEO guys happy
      'imgAlt' => "Captcha Image - Please verify you're human"
  )));

And then to set my own error message:

$captcha->setErrorMessages(array('badCaptcha' => 'My message here'));

When the validation fails I get:

'My message here; My message here'

Why is it duplicating the error and how do I fix it?

like image 889
Richard Parnaby-King Avatar asked Feb 22 '11 09:02

Richard Parnaby-King


1 Answers

After spending a LOT of time trying to get this to work, I've ended up setting the messages in the options of the constructor

$captcha = new Zend_Form_Element_Captcha(
  'captcha', // This is the name of the input field
  array(
    'captcha' => array(
      // First the type...
      'captcha' => 'Image',
      // Length of the word...
      'wordLen' => 6,
      // Captcha timeout, 5 mins
      'timeout' => 300,
      // What font to use...
      'font' => 'images/captcha/font/arial.ttf',
      // URL to the images
      'imgUrl' => '/images/captcha',
      //alt tag to keep SEO guys happy
      'imgAlt' => "Captcha Image - Please verify you're human",
      //error message
      'messages' => array(
        'badCaptcha' => 'You have entered an invalid value for the captcha'
      )
    )
  )
);
like image 77
Richard Parnaby-King Avatar answered Sep 24 '22 23:09

Richard Parnaby-King