Solved

Forms and special characters

Posted on 2001-07-18
26
747 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now