1
votes

In my model

$form = new \Zend_Form();
$form->addElement('text', 'name', array(
        'validators'    => array(
            array('NotEmpty', true),
            array("stringLength", true, array(1,40))
        ),
        'required'      => true,
        'label'         => "Name",
    ));
return $form;

In my controller, called above model function

if($form->isValid($_POST)) {
  ....
} else {
$form = Product::getForm();
print_r($form->getErrors());
print_r($form->getErrorMessages());
print_r($form->getMessages());
}

I am using Zend Framework.

Here in name field in form, string with more than 40 chars needs to display error messages.

I tried with get error with getErrors() and getErrorMessages(). But none of these function give me error. It returns an empty array on printing the these functions.

Please help me to solve this problem...

2
No problem, just worth mentioning when it's low.Jake N

2 Answers

3
votes

Why make you this call:

$form = Product::getForm();

So you overwrite the old $form variable with its error messages. Try it without these line.

2
votes

The error messages will not be there until you call isValid() on the form, like so

$form = Product::getForm();

if(!$form->isValid($_POST))
{
    print_r($form->getErrors());
    print_r($form->getErrorMessages());
    print_r($form->getMessages());        
}