[dancer-users] UTF-8 in form POST

Warren Young warren at etr-usa.com
Thu Jun 26 14:49:47 BST 2014


I'm getting data corruption when a UTF-8 encoded web page sends form 
data back to Dancer via POST.

As far as I can tell, the browser is doing the right thing and 
submitting the data as UTF-8 -- verified with Firebug -- but when I try 
to retrieve the data with param(), Dancer treats it as something else.

To see this, say "dancer -a utf8form" and edit two of the files:

1. Replace the contents of utf8form/views/index.tt with:

   <form method="post" action="/submit">
     <input name="field" type="text"/>
   </form>

2. Add a POST handler route to utf8form/lib/utf8form.pm:

   post '/submit' => sub {
       debug "Got '", param('field'), "' from form.";
   };

Since my terminal uses UTF-8 and default Dancer apps have UTF-8 in 
config.yml and the generated HTML templates, the debug() call shouldn't 
need any special help, IMO.

Try submitting "Español", for example.


More information about the dancer-users mailing list