zend-framework2zend-formzend-filter

Unfiltered formfields disappear when requesting formdata after submitting


I am trying to use filters inside a form class to filter and validate form field.

I did not create a filter for my password field, and when I print the form data after submit, the password field is the only field that does not passes through, even the key is gone.

I create the form fields like this:

$this->add(array(
        'name'              => 'password_verify',
        'type'              => 'password',
        'options'           => array(
            'label'         => 'Verify password:'
        ),
        'attributes'        => array(
            'required'      => 'required',
            'placeholder'   => 'Verify password here...'
        )
    ));

And adds filters like this inside the getInputFilter() method

$inputFilter->add($factory->createInput(array(
            'name'                  => 'password_verify',
            'filters'               => array(
                array(
                    'name'              => 'StripTags',
                ),
                array(
                    'name'              => 'StringTrim'
                )
            ),
            'validators'                => array(
                array(
                    'name'              => 'identical',
                    'options'           => array(
                        'token'         => 'password',
                    )
                )
            )

I tried to delete the inputFilters for other fields aswell, and they disappears too.

Why does Form only return data that is filtered?

I have printed the postData before its passed on to the form class for validation/filtering, and all the fields are there.


Solution

  • You always need to add a Validator to a Field. The Validator can be empty, but it needs to have a validator attached. The logic of ZF2 is:

    all unvalidated data is evil - period