0
votes

New to ZF2 and trying to understand some of its nuances.

I have a couple of questions:

Question 1

I'm using configuration to set out the input filters for a form field (example below). When you have a filter and a validator on the same element like this does the filtered data get passed to the validator? So in the example below if I entered " Hello world " with a load of white space would that white space be stripped from the string before the validator evaluates it?

'name' => array(
            'required' => true,
            'filters'  => array(
                array('name' => 'Zend\Filter\StringTrim'),
            ),
            'validators' => array(
                array(
                    'name' => 'Zend\Validator\StringLength',
                    'options' => array(
                        'min' => 3,
                        'max' => 11
                    ),
                ),
            ),
        ),

Question 2

I've seen examples where people have set a filter using just a name e.g. 'strtolower' as per the below code. What I can't figure out is whether this alias is set somewhere like with validators in ValidatorPluginManager. Where are the aliases set for filters?

    'name' => array(
            'required' => true,
            'filters'  => array(
                array('name' => 'strtolower'),
            ),
            'validators' => array( /*validator stuff*/),
        ),

Really appreciate any advice as I've been crunching the docks but can't find answers to these questions.

Drongo

2

2 Answers

1
votes

Question 1

Yes, when using input filters the value will first be filtered before validation takes place.

Question2

Have a look at the FilterPluginManager for all the aliases you can use for the "stock" filters.

Check ValidatorPluginManager for an overview of the validators.

0
votes

@BramGerritsen is very right in his answer so I upvoted his, but here is some additional information to his answer for your Question 1:

There are special cases where validation happens before filtering. An example is the FileInput class. With file upload the files should be validated before we do anything else so that any validation will be done prior to any filters that may rename/move/modify the file... (check the link).
I could imagine other people having custom input classes where they do the same (I actually have some classes like that myself).