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

encoding

Status
Not open for further replies.

amiw

Programmer
Apr 1, 2003
113
GB
Below are my two pages, a form posting to another page.
In the hidden field I have the value 222!

----------
form.asp
----------

<form name="form1" method="post" action="form_receive.asp">
<input name="test" type="hidden" value="222!">
<input type="submit" name="Submit" value="Submit">
</form>

-----------------
form_receive.asp
-----------------
Response.write request.form


Why does the form_receive.asp display

test=222%21&Submit=Submit

I've tried server.htmlencode and server.urlencode, any ideas? why I get %21 instead of !

If I do
Response.write Server.HTMLEncode(Request.form("test")) it works fine.

 
you see those characters becasue of the spaces and the quotes '' that you have in your querystring...

-DNG
 
Maybe Response.Write(), yields %21 to represent the exclamation point because the ! can be a meaningful character in an HTML document. Server.HTMLEncode maps special characters into a form that a browser will not mistake for HTML tags, for example < becomes &lt; So it may be with the !. For example, <!DOCTYPE >.

But, when we simply use an ! in web page content there is no problem. That is, Response.Write("!") does not lead to %21.

Also looking at permissable characters in a URL, ! is allowed. See
So this is peculiar to Response.Write( Request.Form ).

Checking Response.Write( Request.Form("test") ) yields the !, not %21.

So yes, it is peculiar to
Code:
Response.Write( Request.Form )
.

The expression Request.Form probably refers to an object, not a string. Behind the scenes the ASP processor has determined that in the context of Response.Write(), it would be most appropriate to return a string instead of an object, to return the content of the REQUEST, the form data, as if it were a querystring. Why this should result in transforming ! to %21 is still a mystery.

So I take two lessons from this. Never let Microsoft do your thinking for you (i.e., if you mean Request.Form("test").Item() then say so). And avoid the use of punctuation characters in names and values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top