Zend Framework 2 - Integer Form Validation

前端 未结 3 1228
忘掉有多难
忘掉有多难 2021-02-10 00:50

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

相关标签:
3条回答
  • 2021-02-10 01:37

    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,
                      ),
                  ),
                ),
            )));
    
    0 讨论(0)
  • 2021-02-10 01:38
     array(
                            'name' => 'not_empty',
                        ),
                        array(
                            'name' => 'Digits',
                        ), array(
                            'name' => 'Between',
                            'options' => array(
                                'min' => 0,
                                'max' => 1,
                            ),
                        ),
    
    0 讨论(0)
  • 2021-02-10 01:42

    this is a old topic but i should mention that Filters don't cause validation errors, they work in background and do their jobs silently .

    for example Int filter will remove any non-integer from the input , so when you do $form->getData() the field with the Int filter will only have integer values and 0 if its empty.

    0 讨论(0)
提交回复
热议问题