Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a Perl CGI display Japanese chars sent by an HTML form? 1

Status
Not open for further replies.

GLCHY

Programmer
Mar 16, 2002
3
US
Hi,

as im plunging in the realm of internationalization, im getting more and more confused!

Ok here goes -

I have an HTML form with the charset=euc-jp, my IE browser 6.0 supports that encoding, PERL 5.6, Solaris 2.6.

My HTML form have 2 input fields which is submitted to a perl cgi which simply displays them back on the browser.

<HTML>
<HEAD>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=euc-jp&quot;>
</HEAD>
<BODY>
<FORM NAME=TESFORM METHOD=GET ACTION=&quot;<TABLE>
<TR>
<TD VALIGN=TOP>Your First Name: </TD>
<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=&quot;FIRST_NAME&quot;></TD></TR>
<TR>
<TD VALIGN=TOP><Last Name: </TD>
<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=&quot;LAST_NAME&quot;></TD></TR>
<TR<INPUT TYPE=SUBMIT NAME=TYPE VALUE=&quot; Submit &quot;><BR></TD></TR>
</TABLE></FORM></HTML>

My perl cgi script (proc_form.cgi):
#!/usr/local/bin/perl

use CGI;

&CGI::ReadParse ;

$fname = $in{FIRST_NAME};
$lname = $in{LAST_NAME};

print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML><BODY>\n&quot;;
print &quot;<BR>FNAME:$fname\n&quot;;
print &quot;<BR>LNAME:$lname\n&quot;;
print &quot;</BODY></HTML>\n&quot;;


Now, when i submit the form with some japanese chars as first name (copy-pasted from a japanese website and NOT input thru a japanese keyboard) and some latin chars as last name, the CGI correctly displays the last name but my first name is all 'garbage'. It does NOT matter whether i use POST rather than GET. I changed the charset to SHIFT_JIS and UTF-8, i still get garbage displayed back by the CGI.

I noticed that my url thru the GET method is:

My question is what should i do to get the japanese chars i send thru my form to be displayed correctly by the CGI? And why is my last name (&quot;Smith&quot;) correctly displayed by the CGI even tho i preset the charset in the HTML form to euc-jp?

Thanks a lot,

GC
 
There is the Perl pragma

use locale

along with several POSIX setting you could try. I've not used it myself, but I know a few who have with success. There is a FAQ of sorts online, which you might find useful.


I know Damian Conway has looked into alot of Latin language coding of Perl with his Lingua series, but don't know if anyone has delved into the Japanese character sets. However, the FAQ mentioned above will hopefully be a good starting point.

HTH,
Barbie. Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top