-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 14/11/2003, at 8:27 AM, Jim Kutter wrote:
Doh.
FWIW, I bypassed the problem by removing 'goofy' characters (accented 'e' in this case) from the item/head field, but that doesn't guarantee the problem won't come back in the future.
Is there any way I can enforce a certain charset in my forms, so the non-supported characters don't enter the system in the first place? And is there a way to see what character set a given string is in?
Simple solution is to set the Content-Type header to your preferred character set, and then get Zope to convert the 8bit encoded results from your form to Unicode using its casting facility: <tal:x condition="python:request.RESPONSE.setHeader('Content-Type','utf8')" /> <form action="foo" accept-charset="utf8"> <input name="bar:ustring:utf8" value="Zope converts this to a Unicode string" /> <input type="submit" /> </form> Alternatively, if you want to avoid the possibility of people messing with your forms or submitting data in non standard ways (typing a query string into a URL for example), you need to decode the strings in your form handler: def handleFoo(self, bar, REQUEST=None): ''' docstring ''' if type(bar) != type(u''): bar = bar.decode('utf8') # Needs to match the content type of your form [ ... ] Some insight into this issue can be found at http://lists.oasis-open.org/archives/wsrp-markup/200208/msg00012.html I recommend sticking with UTF8 as your encoding in case somebody enters Japanese into your forms. - -- Stuart Bishop <stuart@stuartbishop.net> ☞ http://www.stuartbishop.net/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (Darwin) iD8DBQE/tE60AfqZj7rGN0oRAuDXAJ9hEW+XVTvZkd2QmeiHP968hzsm/ACgjr4E N2xBPqnXYGtvcs1iYgNvQh0= =9B+5 -----END PGP SIGNATURE-----