src/Form/Base.php
protected function addInputFilter()
    {
        $sm = $this->getServiceLocator();
        if (empty($sm)) {
            throw new \Exception('Form must be initialized using FormElementManager, refer document for more information');
        }
        $config = $sm->get($this->moduleService)->config();
        foreach ($this->getFormElements() as $element) {
            // If element by name filters exist with value false, do not apply the filter for the element.
            if (array_key_exists('filters', $element) && false === $element['filters']) {
                continue;
            }
            // If validator by name not empty exist then set required to true, else. Set required to false
            $element['required'] = false;
            if (array_key_exists('validators', $element) && is_array($element['validators'])) {
                foreach ($element['validators'] as $validator) {
                    if (in_array($validator['name'], array('NotEmpty'))) {
                        $element['required'] = true;
                    }
                    // Allow validation on empty values for Callback validator
                    if (in_array($validator['name'], array('Callback'))) {
                        $callBackValidatorExist = true;
                        $element['allow_empty'] = true;
                        $element['continue_if_empty'] = true;
                    }
                }
            }
            if (array_key_exists('type', $element)) {
                unset($element['type']);
            }
            $element['allow_empty'] = true;
            $element['continue_if_empty'] = true;
            $this->inputFilter->add($this->inputFactory->createInput($element));
        }
        return $this->inputFilter;
    }
protected function addInputFilter()
    {
        $sm = $this->getServiceLocator();
        if (empty($sm)) {
            throw new \Exception('Form must be initialized using FormElementManager, refer document for more information');
        }
        $config = $sm->get($this->moduleService)->config();
        foreach ($this->getFormElements() as $element) {
            // If element by name filters exist with value false, do not apply the filter for the element.
            if (array_key_exists('filters', $element) && false === $element['filters']) {
                continue;
            }
            // If validator by name not empty exist then set required to true, else. Set required to false
            $element['required'] = false;
            if (array_key_exists('validators', $element) && is_array($element['validators'])) {
                foreach ($element['validators'] as $validator) {
                    if (in_array($validator['name'], array('NotEmpty'))) {
                        $element['required'] = true;
                    }
                    // Allow validation on empty values for Callback validator
                    if (in_array($validator['name'], array('Callback'))) {
                        $callBackValidatorExist = true;
                        $element['allow_empty'] = true;
                        $element['continue_if_empty'] = true;
                    }
                }
            }
            if (array_key_exists('type', $element)) {
                unset($element['type']);
            }
            $element['allow_empty'] = true;
            $element['continue_if_empty'] = true;
            $this->inputFilter->add($this->inputFactory->createInput($element));
        }
        return $this->inputFilter;
    }
protected function addInputFilter ( ) { $ sm = $ this -> getServiceLocator ( ) ; if ( empty ( $ sm ) ) { throw new \ Exception ( 'Form must be initialized using FormElementManager, refer document for more information' ) ; } $ config = $ sm -> get ( $ this -> moduleService ) -> config ( ) ; foreach ( $ this -> getFormElements ( ) as $ element ) { // If element by name filters exist with value false, do not apply the filter for the element. if ( array_key_exists ( 'filters' , $ element ) && false === $ element [ 'filters' ] ) { continue ; } // If validator by name not empty exist then set required to true, else. Set required to false $ element [ 'required' ] = false ; if ( array_key_exists ( 'validators' , $ element ) && is_array ( $ element [ 'validators' ] ) ) { foreach ( $ element [ 'validators' ] as $ validator ) { if ( in_array ( $ validator [ 'name' ] , array ( 'NotEmpty' ) ) ) { $ element [ 'required' ] = true ; } // Allow validation on empty values for Callback validator if ( in_array ( $ validator [ 'name' ] , array ( 'Callback' ) ) ) { $ callBackValidatorExist = true ; $ element [ 'allow_empty' ] = true ; $ element [ 'continue_if_empty' ] = true ; } } } if ( array_key_exists ( 'type' , $ element ) ) { unset ( $ element [ 'type' ] ) ; } $ element [ 'allow_empty' ] = true ; $ element [ 'continue_if_empty' ] = true ; $ this -> inputFilter -> add ( $ this -> inputFactory -> createInput ( $ element ) ) ; } return $ this -> inputFilter ; }
Add input filter to form elements
- Skip filters if value is set to false
- If NotEmpty validator is available, add required element with value true, else set required value to false
- Remove type from element to avoid conflict with input filter

@return Zend\InputFilter\InputFilter
Add input filter to form elements - Skip filters if value is set to false - If NotEmpty validator is available add required element with value true else set required value to false - Remove type from element to avoid conflict with input filter