Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 757
  • Last Modified:

Forms and special characters

Hi, I have a form (in IE 5.5) with a textarea. But when a user enters a special character like the euro-sign and submits the form, it automatically converts this character to €.

I don't like this because I want to HTMLEncode it myself. When I do that I get € for the euro-sign. It's encoded twice now.

How can I prevent this double conversion? I need to encode an entire string which may contain euro-signs.

TIA
0
Epsylon
Asked:
Epsylon
  • 13
  • 6
  • 2
  • +3
1 Solution
 
hongjunCommented:
index.htm
========

<form action="second_page.asp" method="post">
<textarea name="dummy"></textarea>
<input type="submit">
</form>


second_page.asp
=========
<%
Response.Write Server.HTMLEncode(Request.Form("dummy"))
%>


It will did display the correct output.

hongjun
0
 
EpsylonAuthor Commented:
That's the problem. that will show &#8364; in the browser and the source of the document shows &amp;#8364;.

The euro-sign is encoded twice.
0
 
EpsylonAuthor Commented:
Netscape 4.75 works fine by the way.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
EpsylonAuthor Commented:
In IE 5.5:

Response.Write Request.Form("dummy")
results in &#8364;

Response.Write Server.HTMLEncode(Request.Form("dummy"))
results in &amp;#8364;



In Netscape 4.75:

Response.Write Request.Form("dummy")
results in E   (=Euro-sign)

Response.Write Server.HTMLEncode(Request.Form("dummy"))
results in &#8364;


I wish IE does the same as Netscape.
0
 
EpsylonAuthor Commented:
The euro-sign is ALT-0128

?
0
 
DirkVeCommented:
Strange, you get other results the I have.

Here's my example:
Response.Write Server.HTMLEncode(Request.Form("dummy"))
Response.Write "<br>" & Request.Form("dummy")
Response.Write "<br>" & unescape(Server.HTMLEncode(Request.Form("dummy")))

This is the input in the textarea:
&#8364 AND ?

And this is my ouput:
&#8364 AND ?
? AND ?
&#8364 AND ?


As you can see, I used also the function UNESCAPE. Maybe it can help you?
0
 
EpsylonAuthor Commented:
Are you using IE 5.5?
0
 
mgfranzCommented:
How about URLEncode()?
0
 
thunderchickenCommented:
I had the same problem when users could copy and paste information from a Word Document to a text area in a browser.  The only fix I could find was a manual fix using the replace() function, ie, foo=replace(foo,"&#8364;", "E") though, I do not remember if URLEncode(), URLHTML() worked or not
0
 
EpsylonAuthor Commented:
Thanks for the replies everyone. However, as far as I can see, thunderchicken is the only one why really understands the problem. No offence to the others, I appriciate all input.

I'm using the 'POST' method to send the form, so URL coding is not the issue here.

DirkVe, unescape doesn't do anything here.

thunderchicken, I've been thinking about using replace or regexp, but I prefer to disable that automatic conversion. What if someone types 'E &#8364;'? This results in '&#8364; &#8364;'. How do I know which one was meant to be an E and which one was not?  (E=euro-sign)

This is really a big error form Microsoft if there is no way to turn the conversion off.
0
 
hongjunCommented:
Perhaps I am dumb in some way.

hongjun
0
 
thunderchickenCommented:
This is what happened to me:

I worked for a school system that had all these documents in Word Format.  There were about 90 schools with an average of 30 to 200 pages for each document.  We hired some people to put these all on-line, which was put into a MS-SQL 7 Database.  Things like Bullets, Tabs all had a &XXXX; put in.  This was all done through a copy and paste into a textbox, then hit submit.

I really wouldn't say it's an error from microsoft, people are actually copying the special formatting, I believe it's called Unicode, and when it's put on to the clipboard, it is interpreted as that.  When we would display these online, it would show as the &XXXX; format instead of the tab, bullet, etc.  Though it didn't fix the problem, when it was displayed, I wrote a function to translate the information and used a bunch of replace() functions.  This I put into a common include file and called it whenever I had the error.  With 90 different possiblities, it was a quick fix to the problem and no one cared how it was fixed, but they got the &XXXX; out.
0
 
mgfranzCommented:
It's not an error, it's there for security, to prevent someone from sending a special character URL string request.

I understand the question perfectly, but I don't see the point... if the browser is doing the encoding for you, why would you want to control it?  Trying to re-invent the wheel?
0
 
EpsylonAuthor Commented:
Maybe I just didn't explain it well enough  :o)
0
 
EpsylonAuthor Commented:
mgfranz, what if I type '<b>E</b>' and use server.htmlencode to encode it, I get

&lt;b&gt;&amp;#8364;&lt;/b&gt;

I want

&lt;b&gt;&#8364;&lt;/b&gt;
0
 
mgfranzCommented:
Why?  My thinking is this "&#8364" will be misinterpreted...
0
 
EpsylonAuthor Commented:
mgfranz, I want to show everything that I type in a textarea on an ASP page, including the HTML tags like <b> and </b>.

So when I type <b>E</b>, I want to see <b>E</b>. Not a bold E or <b>&#8364;</b>, just <b>E</b>. So the HTML source must be &lt;b&gt;&#8364;&lt;/b&gt;
0
 
mgfranzCommented:
When the textarea is pasted BACK into a page, use the HTMLEncode() function on the string.

<text area value="<%=Server.HTMLEncode(theString)%>">

If I'm following you correctly.
0
 
EpsylonAuthor Commented:
That is what I am doing, but the Euro-sign is already encoded, so it will be encoded again along with the HTML tags.

Btw, I don't necessarily want to paste it back to a textarea. It's more or less what happens here on Experts-Exchange. You type something. Others see exactly what you typed.
0
 
vindevogelCommented:
I face a similar problem ... French words.
We use this in an ASP

Response.CharSet = "iso-8859-1"

This shows all characters correct.
And you can use it in a POST
Action=page.asp method=post, just like you do now ...
     
0
 
EpsylonAuthor Commented:
Thanks for trying to help, vindevogel, but it does not stop the automatic conversion.
0
 
EpsylonAuthor Commented:
If I type the Euro-sign (E) in a textarea and post it to this ASP page

<html>
<head>
<title>Test</title>
</head>
<body>
<%response.write request.form("textfield")%>
</body>
</html>

the IE client gets this source

<html>
<head>
<title>Test</title>
</head>
<body>
&#8364;
</body>
</html>


In Netscape it works fine. I get this:

<html>
<head>
<title>Test</title>
</head>
<body>
E
</body>
</html>
0
 
mgfranzCommented:
You need to play with the character mapping of the page, by default IE uses the latin charset;

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Or;

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

You may need to change it to eastern europe;

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">

Or;

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


Read this, it might enlighten you...

http://www.unicode.org/unicode/faq/unicode_web.html

And http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset4.asp?frame=true

0
 
EpsylonAuthor Commented:
mgfranz, you are a hero!

I use Response.CharSet = "windows-1250" and it works! It also works with the meta tag, but I'll use
Response.CharSet for now.

I upped the points to 150.

vindevogel, I'll post a dummy question for you for the Response.CharSet hint.

Thanks everyone!
0
 
mgfranzCommented:
Are you testing with Netscape 6?  I read somewhere that this would be the first version that would accept special characters without havinng to implement some-sort of character mapping.

Glad you got it.  And thanks,
0
 
vindevogelCommented:
Okay, thanks a lot ...
We use it for French, but I guess with the right Charset, you can do anything.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 13
  • 6
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now