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

Hi all,

Got I'm in troubles with an html form. I'm getting some data from a mysql DDBB, so finally showing it in a form to let the user edit the fields.

I recived the data in hex format, so by means the tr function I'm writing white spaces instead the + symbol, so if theres writed: hello+ferran, the translation should be hello ferran: tr/+/ /. but... what if the user really wants to insert the simbol +?

Any idea?

Many thanks MONKS

20040902 Edit by ysth: add <p> tags, change title from PERL FORMS

Replies are listed 'Best First'.
Re: Encoding spaces in CGI form data
by edan (Curate) on Aug 30, 2004 at 13:21 UTC

    Enter CGI:

    use CGI; my $q = CGI->new(); my $user_input = $q->param( 'user_input' );
    --
    edan

Re: Encoding spaces in CGI form data
by ambrus (Abbot) on Aug 30, 2004 at 15:52 UTC

    That's what the CGI::unescape function for:

    use CGI; print CGI::unescape("hello+ferran%21"), $/; __END__
    prints
    hello, ferran!
Re: Encoding spaces in CGI form data
by ikegami (Patriarch) on Aug 30, 2004 at 15:59 UTC

    Special characters other than spaces are replaced with their UTF-8 value in hex, each byte preceeded by a '%':
    '+' becomes '%2B',
    '%' becomes '%25',
    etc.

    $cgi->param() and $cgi->params() will properly unescape everything for you.

Re: Encoding spaces in CGI form data
by Anonymous Monk on Aug 30, 2004 at 13:22 UTC