-- J DeBord <[email protected]> wrote
(on Tuesday, 14 July 2009, 08:29 PM +0200):
> I've tried to make StripTags leave the href attribute, but it strips it out. I
> can't find the right syntax or it just doesn't work. The <a> tag is left
> intact, every other tag is stripped, but the href and title get stripped as
> well.
> 
> I've also used the fluid interface when adding the Textarea, but changed it to
> what is below in hopes that it would work.
> 
> What am I doing wrong?

What version of ZF are you using?

I did the following using current trunk:

    $element = new Zend_Form_Element_Textarea('foo', array(
        'filters' => array(
            array('StripTags', array(array('a'), array('href', 'title'))),
            'StringTrim',
        ),
        'value'   => '<p>
            This is <a onClick="foo.bar()" href="http://foo.com/"; 
                title="Foo!">linked text</a>.
        </p>',
    ));
    echo $element->getValue();

and got exactly what I expected:

    This is <a href="http://foo.com/"; title="Foo!">linked text</a>.


> <?php
> 
> class Form_NewMessage extends Form_Default {
>    
>     public function init() {
>        
>         $this->setMethod('post');
>        
>         $this->setAttrib('id', 'new_message');
>        
>         $textarea = new Zend_Form_Element_Textarea('message');
>         $textarea->setDecorators($this->_defaultDecorators);
>        
>         $stripTags = new Zend_Filter_StripTags(array('a'), array('href',
> 'title'));
>        
>         $textarea->addFilter('StringTrim');
>         $textarea->addFilter($stripTags);
>         $textarea->setValidators(array());
>         $textarea->setRequired(true);
>         $textarea->setAttrib('cols', 40);
>         $textarea->setAttrib('rows', 2);
>        
>         $this->addElement($textarea);
>        
>         $this->addElement('Submit', 'submit', array(
>             'Decorators' => array('ViewHelper'),
>             'class' => 'submit',
>             'Label' => 'Post Your Message!',
>             'Ignore' => true,
>         ));
>        
>         $this->setDecorators(array(
>             'Description',
>             'FormElements',
>             'Fieldset',
>             'Form'
>         ));
>        
>     }
> }

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to