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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

high end characters and cgi forms

Status
Not open for further replies.

jas33

Programmer
Aug 10, 2005
2
AU

i have a form that get's populated by data off a db. this data usually contains high char html entities. e.g. ■ . which appears as the black box character in my form.
my issue is when submitting/saving the form, i loose the html entity or the black box char. it seems to get converted to some other char.
im using CGI.pm to retireve the form.
one solution was to replace all '&' with '&' however i moved to using htmlarea, a javascript wysiwyg, on my textarea so that no longer works.

any help would be greatly appreciated.
 
Try my subs for encoding & decoding chars like the browser does.

Code:
sub decode{
$input = $_[0];
$input=~s~%25~%~g;
$input=~s~%21~!~g;
$input=~s~%23~#~g;
$input=~s~%24~\$~g;
$input=~s~%5E~\^~g;
$input=~s~%26~\&~g;
$input=~s~%28~\(~g;
$input=~s~%29~\)~g;
$input=~s~%3D~=~g;
$input=~s~%7B~{~g;
$input=~s~%7D~}~g;
$input=~s~%5B~\[~g;
$input=~s~%5D~\]~g;
$input=~s~%3B~;~g;
$input=~s~%3A~:~g;
$input=~s~%27~'~g;
$input=~s~%22~"~g;
$input=~s~%3C~<~g;
$input=~s~%3E~>~g;
$input=~s~%2C~,~g;
$input=~s~%3F~\?~g;
$input=~s~%5C~\\~g;
$input=~s~%7C~\|~g;
$input=~s~%60~`~g;
$input=~s!%7E!~!g;
$input=~s~%0D%0A~\r~g;
$input=~s~%0D%0A~\n~g;
$input=~s~%20~ ~g;
return $input;
}

sub encode{
$input = $_[1];
$input=~s~%~%25~g;
$input=~s~!~%21~g;
$input=~s~#~%23~g;
$input=~s~\$~%24~g;
$input=~s~\^~%5E~g;
$input=~s~\&~%26~g;
$input=~s~\(~%28~g;
$input=~s~\)~%29~g;
$input=~s~=~%3D~g;
$input=~s~{~%7B~g;
$input=~s~}~%7D~g;
$input=~s~\[~%5B~g;
$input=~s~\]~%5D~g;
$input=~s~;~%3B~g;
$input=~s~:~%3A~g;
$input=~s~'~%27~g;
$input=~s~"~%22~g;
$input=~s~<~%3C~g;
$input=~s~>~%3E~g;
$input=~s~,~%2C~g;
$input=~s~\?~%3F~g;
$input=~s~\\~%5C~g;
$input=~s~\|~%7C~g;
$input=~s~`~%60~g;
$input=~s!~!%7E!g;
$input=~s~\r~%0D%0A~g;
$input=~s~\n~%0D%0A~g;
$input=~s~\s~%20~g;
return $input;
}

May need a little modification. But should help.

You could probably put the chars in the fields without encoding, then just run the decode sub on them when CGI.pm passes them to you.

Tony
 
One of the MVP's (not me!) posted this a short while ago. I stole it. I'm not proud... it really is the dogs:-

Code:
sub urlencode {
   my ($value) = @_;
   $value =~ s/([^a-zA-Z_0-9 ])/"%" . uc(sprintf "%lx" , unpack("C", $1))/eg;
   $value =~ tr/ /+/;
   return ($value);
}


Kind Regards
Duncan
 

thanks guys, however it seems like all i need was this on my form page.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
What did you have at the top of your page, just for interest?
ISO-8859-1 (latin-1) ?

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top