Zend form and Zend filter HtmlEntities

我怕爱的太早我们不能终老 提交于 2019-12-07 22:07:20

问题


I have a registration form with a few fields. One of them looks like this:

        $first_name = new Zend_Form_Element_Text('first_name');
        $first_name ->setLabel("First name")
                    ->setRequired(true)
                    ->addFilter(new Zend_Filter_HtmlEntities());

I use the same form for editing user's details. The problem is with the Zend_filter_HtmlEntities. It does the job when I send the form's data to the database, it replaces html special chars with their alternatives. However, when I initialise this form and give it default values from a database record, Zend_filter_HtmlEntities filters those values again and I get some garbage in my input fields.

For example, in first name input field, instead of <b>Name, I get &amp;lt;b&amp;gt; Name

Which means that when the form is rendered with default values, element filters are applied again and < because &lt; :(

Is there an elegant solution to this problem, apart from reformatting the data before it gets passed to the form?


回答1:


Adding the Zend_Filter_HtmlEntities filter, I would avoid entirely. Instead, I'd worry about escaping html entities only when displaying the data back to the user.



来源:https://stackoverflow.com/questions/2051876/zend-form-and-zend-filter-htmlentities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!