0

below code does not displaying the validation message, should i print any varable any where. please advise.

$username = new Zend_Form_Element_Text('username', array('autocomplete' => 'off'));
        $username->setLabel('Username')
                ->setDecorators($elementDecoration)
                ->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty', true, array('messages'=>'Cannot be empty'));


$elementDecoration = array(

            'ViewHelper',
            'Description',
            'Errors',
            array(array('data'  => 'HtmlTag'), array('tag' => 'td')),
            array('Label', array('tag' => 'td', 'placement' => 'prepend')),
            array(array('row'   => 'HtmlTag'), array('tag' => 'tr')),
        );
1
  • i be leave something is going wrong becauseof setDecorators Mar 26, 2013 at 11:28

2 Answers 2

0

You want to remove the setRequired function from your element. This function is overriding the NotEmpty validator. Since you are checking for NotEmpty, you can remove setRequired in order to display your own message.

0

Try this

$username->setLabel('Username')
                ->setDecorators($elementDecoration)
                ->setRequired(true)
                ->addErrorMessage('Cannot be empty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

Make sure that the decorators used are correct.

$element->setDecorators(array(
    'ViewHelper',
    'Description',
    'Errors',
    array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')),
    array(array('td' => 'HtmlTag'), array('tag' => 'td')),
    array('Label', array('tag' => 'td')),
));
2
  • i just want to display validation message when the user is not entered, but currently it displaying the " Value is required and can't be empty " message every field next. how to display validation message only when user is not entered. Mar 26, 2013 at 11:33
  • plz check my setDecorators Mar 26, 2013 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.