Zend input Filter in ZF3 - filtering a date

813 Views Asked by At

I'm trying to add date Filters to my form in ZF3. So in my FooForm I implemented the InputFilterProviderInterface and down in my method I got :

public function getInputFilterSpecification()
{
    return [
        'BarInput' => [
            'validators' => [
                [
                    'name' => StringLength::class,
                    'options' => [
                        'min' => 2,
                        'max' => 5,
                    ],
                ],
            ],
            'filters' => [
                [
                    'name' => 'Zend\Filter\Date?'
                ]

So for the filters I have no idea what to put for a date (I checked the documentation, but I was clueless). My dateInput is a string and I want to output a \DateTimeImmutable, for saving it correctly in my controller.

1

There are 1 best solutions below

0
On

I found the answer in the vendor file :

'filters' => [
                [
                    'name' => 'Zend\Filter\DatetimeFormatter',
                    'options' => [
                        'format' => 'Y-m-d',
                    ],
                ]
            ]

Be careful about the format because Chrome format sent is not as it displays.