Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts

    request.form encoding

    when i just do Response.Write Reqest.Form it enters spaces as + and semicolons as %3B and ' and " as %27 and %22 etc.. is there any way to quickly get everything back to ; ' " etc (i tried server.urlencode() and server.htmlencode() but neither do it

    i suppose i could probably do a for each loop and just write it to a string (eg Request.Form("field1") comes out as "hello everyone" but in request.form it comes out as field1=hello+everyone so maby
    Code:
    Function URLDecode(strRawFormData)
    	For Each frmField in strRawFormData
    		URLDecode = URLDecode & frmField & "=" & strRawFormData(frmField) & "&"
    	Next
    	URLDecode = Left(URLDecode, Len(URLDecode)-1)
    End Function
    
    Response.Write "Raw Request.Form = " & Request.Form & "<br>"
    Response.Write "New Request.Form = " & URLDecode(Request.Form)
    
    'Returns a result like this:
    'Raw Request.Form = field1=hello+everyone%2C&field2=how+are+you+doing+today%3F
    'New Request.Form = field1=hello everyone,&field2=how are you doing today?
    but i dont know if its the best way of doing this (obvisouly a built in function would be better than a loop)
    Last edited by ghell; 12-13-2004 at 11:53 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    When you output the Request.Form collection, it displays the URL-encoded form data but if you retrieve each item in the collection, the data is automatically decoded.

    'Raw Request.Form = field1=hello+everyone%2C&field2=how+are+you+doing+today%3F

    response.write(request.form("field1")) 'outputs hello everyone,
    response.write(request.form("field2")) 'outputs how are you doing today?

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    pfft glen ur sposed to be useful (thats why i thank you every time i post )

    i already knew that the Request.Form(..) decoded the element of Request.Form .. thats why i put that code there.. but i wondered if there was a built in function rather than the one i made that does the same thing (since there is one for the other way with server.urlencode)

    so some sort of server.urlDEcode() would be useful but that isnt there so if something else did it itd be great.. the function i wrote while writing this post earlier was fine but i didnt know if there was a better way

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    There is Server.URLDecode function method in ASP.NET but not in classic ASP.

  • #5
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    okidoki, thanks m8.. ill just use that function then

    i wasnt sure if it actually was the reverse of urlencode or not btw


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •