problem with input elements and unicode/utf-8
Zope: 2.10.2 Python: 2.4.4 I am not sure if this is a zope problem or a browser problem or a lack of my understanding of webservers and/or utf-8 & unicode but here it is: I have a page template with a form and a textarea input element. The value for the element comes from a database (MySQL) field. The database field contains utf-8 encoded text (includes the bullet and registered characters). When the page is displayed in Firefox (version 1.5.0.9) it displays fine. However when the page is displayed in IE 6 (or 7), it shows garbage characters for the bullet and registered characters. What I find as strange is that if the same field is displayed as just text (i.e. just in a td element rather than in an input element) it displays fine in IE. My page template has the following headers: <html metal:define-macro="page" tal:define="dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;; charset=utf-8');" > <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> Firefox reports the page encoding as UTF-8 with meta: content-type text/html; charset=utf-8 Input element: <textarea cols="50" name="detail_desc" rows="10" tal:content="record/detail_desc | nothing"></textarea><br> I have also tried adding accept-charset="utf-8" to the form element I have been able to fix the problem by adding this to my zope.conf: <cgi-environment> HTTP_ACCEPT_CHARSET utf-8 </cgi-environment> I don't understand why this "fixes" the problem or if it is the correct way to resolve this. Any comments would be appreciated Thanks, Daryl. -- Daryl Daly, B.Sc. Chief Programmer/Business Analyst daryld@norco.com Norco Products Ltd. Really Cool Bikes!!! Norco __O Tel: 604-552-2930 ext 205 Performance =\ \ Fax: 604-552-2948 Bikes (=)/(=) www.norco.com 1465 Kebet Way, Port Coquitlam, British Columbia, V3C 6L3
--On 15. Februar 2007 11:40:49 -0800 Daryl Daly <daryld@norco.com> wrote:
What I find as strange is that if the same field is displayed as just text (i.e. just in a td element rather than in an input element) it displays fine in IE.
My page template has the following headers: <html metal:define-macro="page" tal:define="dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;; charset=utf-8');" > <head> <meta http-equiv="content-type" content="text/html; charset=utf-8">
This should be sufficient to display utf8 content.
Firefox reports the page encoding as UTF-8 with meta: content-type text/html; charset=utf-8
Input element: <textarea cols="50" name="detail_desc" rows="10" tal:content="record/detail_desc | nothing"></textarea><br>
I have also tried adding accept-charset="utf-8" to the form element
This has applies only when you submit the form.
I have been able to fix the problem by adding this to my zope.conf: <cgi-environment> HTTP_ACCEPT_CHARSET utf-8 </cgi-environment>
Should not play a role here.
I don't understand why this "fixes" the problem or if it is the correct way to resolve this.
Unlikely. Does it work with older Zope versions? -ak
I have been able to fix the problem by adding this to my zope.conf: <cgi-environment> HTTP_ACCEPT_CHARSET utf-8 </cgi-environment>
Should not play a role here.
However, if I remove it & restart zope, the problem comes back :)
I don't understand why this "fixes" the problem or if it is the correct way to resolve this.
Unlikely. Does it work with older Zope versions?
Previously the application was running in Zope 2.8 without this problem. I have been making various changes to the application to make it work with 2.10 (fixing unicode errors, etc) but the database data has not changed (has always been utf-8) and I don't think the way the input element is generated has changed. If it makes a difference, the page header (tal:define="dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;; charset=utf-8');") is something I have added recently (in conjunction with the upgrade). Previously only the meta http-equiv ... was on the page.
-ak
Daryl
I have setup a test case which seems to show the problem. This test removes the database component. New install of zope 2.10.2: Zope Version (Zope 2.10.2-final, python 2.4.4, linux2) Python Version 2.4.4 (#1, Oct 23 2006, 13:58:00) [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] System Platform linux2 I created a page template which contains: <html tal:define="dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;; charset=utf-8');" > <head> <title tal:content="template/title">The title</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> </head> <body tal:define="test_str python:u'This is a test \u00e9 \u00ae \u2022 \u2024 \u2219 \u03b2'.encode('utf-8')"> <span tal:content="test_str"></span> <form> <input name="t1" value="" tal:attributes="value test_str"> </form> </body> </html> When this page is viewed in Firefox (v 1.5.0.9), it shows the characters correctly. When viewed in IE6, the non-ascii characters show as garbage. If I add this to the zope.conf: <cgi-environment> HTTP_ACCEPT_CHARSET utf-8 </cgi-environment> the non-ascii characters show correctly in IE6 (except one of them shows as a box - there is no 'garbage') Is this zope.conf setup required for IE6 or am I doing something wrong? Thanks, Daryl.
participants (2)
-
Andreas Jung -
Daryl Daly