[Catalyst] utf8 chars in form elements
Johan Lindström
johanl at DarSerMan.com
Mon Nov 28 11:05:58 CET 2005
I had a problem and was wondering whether my solution was any good:
* Problem *
In the browser, I enter "Lindström" in a name field and save it to the
database.
In the view template this value looks nice:
[% item.$column | html %] --> Lindström
In the form, as the value of an input element, in the edit template, the
value looks weird, with ö being rendered as two chars (the multi-byte utf8
char presumably):
[% item.to_field(column).as_HTML %] --> <input type="text"
value="Lindströ"m">
The browser uses utf-8 from the HTTP header (and/or the <meta> content
type, but it doesn't seem to matter that much). That's not a problem.
In SQLite I can see the double char when looking at the table with dbish,
but Perl seems to handle that correctly, because the ö is there in the
variable value when I look at it.
Class::DBI::AsForm emits HTML::Element objects. The problem seems to be
HTML::Element's as_HTML method which calls
HTML::Entities::encode_entities() and interprets the ö as two chars.
* Solution *
My solution was to explicitly leave everything alone, except for the
"normal" HTML chars:
[% item.to_field(column).as_HTML('<>&"\'') %] --> Lindström
Now... is this a good solution? The right place to solve it? Is it the
right thing?
/J
More information about the Catalyst
mailing list