Zend Form addFilter StripTags 不剥离标签 [英] Zend Form addFilter StripTags not stripping tags

查看:24
本文介绍了Zend Form addFilter StripTags 不剥离标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一点帮助,用 Zend_Form 清理一些东西并向元素添加过滤器.现在我的印象是,当您向表单添加过滤器时,当表单发布时,该过滤器作为控制器中调度的一部分执行.

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.

然而,当我测试我的表单时,过滤器 StripTags 似乎没有运行,我正在获取数据中包含 HTML 标签的数据.

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')

但是,如果我将一些带有 html 标签的数据放入文本区域,然后使用

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){
    ...

数据返回时带有标签.它仅在我通过 strip_tags() 函数传递数据时删除.

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

我想我的问题是应该使用 StipTags 过滤器,如果是,为什么不呢?我在这里错过了什么.

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

推荐答案

您没有发布关于调用 isValid 后如何访问数据的代码.IIRC 过滤器只有在您通过 $form->getValue('someElement') 或类似的东西访问数据时才会生效.

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.

这篇关于Zend Form addFilter StripTags 不剥离标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆