Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 2 - Integer Form Validation

I've got the following problem. I wrote (based on the tutorial) a form validation. The text fields work just fine but the integer field behave odd.

This is my validator:

        $inputFilter->add($factory->createInput(array(
            'name'     => 'zip',
            'required' => false,
            'filters'  => array(
                array('name' => 'Int'),
            ),
        )));

It lies within my Entity.php like the other filters. The odd thing is that this one accepts not even a string but ignores the required when I set it to true. I tried to replace Int with Digits which then causes the form to accept required but still accepts strings.

Any ideas? Thanks!

like image 447
Ron Avatar asked Dec 18 '12 10:12

Ron


1 Answers

Try using the Between validator:

$inputFilter->add($factory->createInput(array(
            'name'     => 'zip',
            'required' => true,
            'filters'  => array(
                array('name' => 'Int'),
            ),
            'validators' => array(
              array(
                  'name' => 'Between',
                  'options' => array(
                      'min' => 1,
                      'max' => 1000,
                  ),
              ),
            ),
        )));
like image 51
Reshil Avatar answered Oct 12 '22 16:10

Reshil