开发者

HTMLtags in input field

I hav开发者_如何学Goe a question about inserting values into an input field from my MYSQL DB.

First I have a form to save data from an inputfield to the database. An extra script filters diacrits Á=>Á to html code. So Állo will be saved like Állo

When I insert the data from the DB to a 'div' it shows Állo. When I insert the data into a input field it shows Állo

What am I doing wrong

I use JQUERY to save data to the DB with the $.post method without pagerefresh. I also get the data from the DB with JQUERY $.post method without pagerefresh.

Hope somebody can help.


you really shouldn't save htmlentities to your database. you should instead save Állo and use htmlspecialshars($my_value_from_db); if its needed (this is php don't know whats runnung on your server, but there are similar functions for perl or other languages). if you can't change the saving process or correct al old entries, you could use html_entity_decode($bla) for values that are shown in input-fields (this is php again)


You are inserting HTML into the div, but setting the DOM value property of the input directly.

An HTML entity is converted to what it represents in HTML, but the value property expects text so doesn't attribute any special meaning to the &.

You should be storing the actual data in the database, not an HTML view of it. Conversion to HTML should be handled on the way out of the server side program (in the View if you are using an MVC design pattern).


Have a script that reverses what the encoding script does and call it when you output to the form fields.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜