views:

1215

answers:

1

Hi,

I need a little help clearing something up with Zend_Form and adding filters to an element. Now I was under the impression that when you add a filter to the form that, when the form is posted that filter was executed as part of dispatch in the controller.

However when testing my form to my horror the filter StripTags doesn't seem to be running and I am getting the data with the HTML tags in the data.

My Form element looks like this.

$address1 = new Zend_Form_Element_Textarea('address1');
    $address1->addFilter('StripTags')
        ->addFilter('StringTrim')            
        ->setAttrib('cols', 30)
        ->setAttrib('rows', 5)
        ->removeDecorator('DtDdWrapper')
        ->removeDecorator('label')
        ->removeDecorator('HtmlTag')

However if I put in the text area the some data with html tags in it and then check the form is valid using

$formData = $this->_request->getPost();
if($form->isValid($formData){
    ...

The data comes back with the tags in it. It only removed when I pass the data through the strip_tags() function.

I suppose my question is should the StipTags filter if so why isn't it? What am I missing here.

+3  A: 

You didn't post code on how you're accessing the data after calling isValid. IIRC the filters will only take effect if you access the data via $form->getValue('someElement') or something along those lines.

Jani Hartikainen
Thanks I was pulling the data direct from the $formData array. Works now when getting the value from the form object.
Grant Collins