masteve00 has asked for the wisdom of the Perl Monks concerning the following question:

I have a PERL script which process web forms. When some fields are not filled out in a form, it returns an error page. When I hit the BACK button on IE 6, the form does not dislay UTF 8 characters at all. But the same code works in Mozzila Firefox. What is the problem? Thanks.
  • Comment on UTF 8 character not displaying after PERL script

Replies are listed 'Best First'.
Re: UTF 8 character not displaying after PERL script
by dakkar (Hermit) on Mar 23, 2005 at 15:10 UTC

    It's a bug in IE. There is (was?) a similar bug in Safari. What happens is that the browser does not re-parse all the information it has on the page when loading it from the cache, and so it creates the form control in a different way than the first time. What it boils down to is exactly what you see: you put some non-ASCII character in a field, submit, back, and your characters are mangled or gone. There is nothing you can do to fix it, you can only work around it.

    I'd second the suggestion of giving the error together with the form, pre-filled with the submitted values.

    -- 
            dakkar - Mobilis in mobile
    

    Most of my code is tested...

    Perl is strongly typed, it just has very few types (Dan)

Re: UTF 8 character not displaying after PERL script
by Thilosophy (Curate) on Mar 23, 2005 at 07:09 UTC
    What happens when you hit the back button in the browser should not be affected by anything the script does (nor can it be influenced by it). That would be a purely client-side (browser) issue.

    I am not sure how this has anything to do with the characters being UTF-8 or not. Does it display non-UTF8 characters correctly? In any case, you have to make sure that you have the character set correctly specified in the HTTP headers and/or the HTML file itself. Different browsers have different logic to figure out the character set, and if the problem you describe only happens with non-Ascii characters, it could be caused by the browser getting things mixed up.

Re: UTF 8 character not displaying after PERL script
by inman (Curate) on Mar 23, 2005 at 09:27 UTC
    There several ways to suggest the character encoding of an HTML page presented by a browser. The two that immediately spring to mind are the content-type HTTP header with a character set and the equivalent meta tag. The latter has the advantage that it is actually part of the page and should be available at any time.

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    update: The following reference may be useful - http://www.w3.org/International/O-charset

Re: UTF 8 character not displaying after PERL script
by jbrugger (Parson) on Mar 23, 2005 at 08:13 UTC
    What i mostly do, is represent the same page with an error message above, or as popup. The form is filled again with the values of the just submitted form.
    Then the user doensn't even need the back-button.
    Or use JavaScript for simple (front-end) form validation.
    But anyway, i don't think it has anything to do with the UTF 8 chars.
    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.