Cawa
Cawa

Reputation: 1299

How to filter zf2 forms?

I'm trying to add filters for my form elements

$this->add(array(
        'name' => 'name',
        'attributes' => array(
            'type' => 'text',
            'required' => true,
        ),
        'options' => array(
            'label' => 'Name',
        ),
        'filters' => array(
            array('name' => 'StringTrim'),
            array('name' => 'StripTags'),
        )
    ));

but I still can add some tags in this element, what am I doing wrong?

Upvotes: 0

Views: 4336

Answers (1)

Nikolai Senkevich
Nikolai Senkevich

Reputation: 2390

Create two classes one for form another for filter and set filter for your form.

$form = new Form\CommentForm();
$form->setInputFilter(new Form\CommentFilter());
return $form;

for more info see https://github.com/nsenkevich/comment/tree/master/Comment

Upvotes: 2

Related Questions