[Catalyst] Re: Catalyst, utf8 in form element type text

Aristotle Pagaltzis pagaltzis at gmx.de
Mon May 5 14:39:47 BST 2008


* Marius Kjeldahl <mariusauto-catalyst at kjeldahl.net> [2008-05-05 00:20]:
> Everything seems to work fine

“Seems” being the operative word.

> with one small exception. Whenever I have a HTML form input
> type=text with an international character and the form
> validation fails, so the default value of the input field
> contains the international character, the rest of the html
> document does no longer display international characters
> correctly.

That is because all of that was not marked as character data to
begin with. When Perl tries to concatenate it with a Unicode
string, it sees byte strings so it decodes them as Latin-1. Then
all the UTF-8 multibyte characters turn into gremlins.

> I'm guessing the browser detects that the document contains
> some element that is not proper utf8, and disables utf8
> altogether before displaying whenever the input field contains
> an international characters.

You’re probably wrong about that guess. What headers do you send?

Do you use `<meta http-equiv="Content-Type">`? (Bad idea, btw.)

> If I remove the international character from the input field
> and resubmit, everything is displayed correctly again. […] The
> input field value is set in the template from the
> $c->req->parameters passed in the stash.

Are you using Catalyst::Plugin::Unicode?

> So my question is what's the best way to handle this?

Did you tell Template Toolkit or whatever template engine you use
that the templates are in UTF-8?

> Can an input value in a form handle a utf8 encoded string at
> all

Yes.

> and if so how can I convince it my string is utf8, and if I do
> does the browser detect it automagically?

No, the headers must be set correctly.

> Any pointers?

In addition to the above? Check out encoding::warnings.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list