Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Forms and special characters

Posted on 2001-07-18
26
Medium Priority
?
756 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 
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 600 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 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