Solved

Forms and special characters

Posted on 2001-07-18
26
749 Views
Last Modified: 2011-09-20
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
Comment
Question by:Epsylon
  • 13
  • 6
  • 2
  • +3
26 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6293456
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6293543
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6293548
Netscape 4.75 works fine by the way.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 13

Author Comment

by:Epsylon
ID: 6293572
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6293727
The euro-sign is ALT-0128

?
0
 
LVL 2

Expert Comment

by:DirkVe
ID: 6293730
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6293764
Are you using IE 5.5?
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6294059
How about URLEncode()?
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6294098
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6294295
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
 
LVL 33

Expert Comment

by:hongjun
ID: 6294309
Perhaps I am dumb in some way.

hongjun
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6294328
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
 
LVL 18

Expert Comment

by:mgfranz
ID: 6294330
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6294344
Maybe I just didn't explain it well enough  :o)
0
 
LVL 13

Author Comment

by:Epsylon
ID: 6294381
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
 
LVL 18

Expert Comment

by:mgfranz
ID: 6294444
Why?  My thinking is this "&#8364" will be misinterpreted...
0
 
LVL 13

Author Comment

by:Epsylon
ID: 6294506
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
 
LVL 18

Expert Comment

by:mgfranz
ID: 6294563
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6294621
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
 
LVL 4

Expert Comment

by:vindevogel
ID: 6297785
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6297912
Thanks for trying to help, vindevogel, but it does not stop the automatic conversion.
0
 
LVL 13

Author Comment

by:Epsylon
ID: 6297939
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
 
LVL 18

Accepted Solution

by:
mgfranz earned 150 total points
ID: 6298355
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
 
LVL 13

Author Comment

by:Epsylon
ID: 6298639
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
 
LVL 18

Expert Comment

by:mgfranz
ID: 6298675
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
 
LVL 4

Expert Comment

by:vindevogel
ID: 6298697
Okay, thanks a lot ...
We use it for French, but I guess with the right Charset, you can do anything.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question