views:

81

answers:

1

Eariler I happily used the following code for creating form elements (inside Zend_Form descendant):

        //Set for options
        $this->setOptions(array(
            'elements' => array(
                'title' => array(
                    'type' => 'text',
                    'options' => array(
                        'required' => true,
                        'label' => 'Title',
                        'filters' => array('StringTrim'),
                        'validators' => array(
                                array('StringLength', false, array('minLength'=>1, 'maxLength'=>50)),
                        ),
                   )
                )

));

But now I've noticed that validators are not working.. I suspect this might be due to zend updates..

Does anyone face this problem?

+1  A: 

I'm not sure if there was an API change that affected this or not, but the syntax I use is:

$this->addElements(array(
    array('text', 'title', array(
        'required'   => true,
        'label'      => 'Title',
        'filters'    => array('StringTrim'),
        'validators' => array(
                array('StringLength', false, array('min'=>1, 'max'=>50)),
        ),
    )),
));

Edit: updated the StringLength validator options keys

awgy
Weird.. but this does not work either.If I add var_dump($this->getElement('title')->isValid('XX')); right after the code you suggested above (but 'minLength'=>4), it will return true, even though the lenghth is equals to 2.
Pavel Dubinin
Try changing `array('minLength' => 1, 'maxLength' => 50)` to `array('min' => 1, 'max' => 50)`. I would bet this is the problem. Sorry I overlooked this earlier.
awgy
ah sure, thanks
Pavel Dubinin