Houx
Houx

Reputation: 265

Validator in Zend Framework?

I use validator to test if login exist in database and it works, but after adding decorators for the Zend form, validator error message don't display any more.

the code:

$this->setName("companyadd");

        $comp = new Zend_Validate_Db_NoRecordExists('company', 'name');
        $comp->setMessage("This company exists!!!!");

        $name = new Zend_Form_Element_Text('name');

        $name->addValidator($comp);
        $name->setAttrib('size', '45');
        $name->setLabel('Company Name')
                ->setAttrib('class', 'companyinputs');
        $submit = new Zend_Form_Element_Submit('submit');
        $this->addElements(array( $name, $submit));

        $this->setElementDecorators(
            array(
                'ViewHelper',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array('Label', array('tag' => 'td', 'class' => 'companylabel')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => 'signuptr'))
        ));
        $submit->setDecorators(
            array(
                'ViewHelper',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array(array('emptyrow' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element', 'placement' => 'PREPEND')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
        ));
        $this->setDecorators(
            array(
                'FormElements',
                array('HtmlTag', array('tag' => 'table', 'class' => 'signuptable')),
                'Form'
        ));

Upvotes: 1

Views: 109

Answers (1)

ilanco
ilanco

Reputation: 9957

You forgot to add errors to the decorator.

$this->setDecorators(array(
    // add this line
    'Errors',

    'FormElements',
     array('HtmlTag', array('tag' => 'table', 'class' => 'signuptable')),
     'Form'
));

Upvotes: 3

Related Questions