How to unencode HTMLencoded strings ?

Results 1 to 3 of 3

Thread: How to unencode HTMLencoded strings ?

  1. #1
    Join Date
    Dec 1969

    Default How to unencode HTMLencoded strings ?

    Hi !<BR><BR>I&#039m trying to find a way to unencode a string previously encoded using method server.HTMLEncode(). <BR>I&#039m using an ASP script to check HTML forms (by verifying that every requested fields aren&#039t empty and so on). If the form&#039s not valid, the script displays the form back with flags highlighting the fields that need to be completed. The data previously submitted is HTML encoded and put as default values in the fields...<BR>Problem is that if the form&#039s still not valid on second time, the data would be HTMLencoded a second time and become unreadable...<BR><BR>Any hint ?? Thanks in advance !

  2. #2

    Default RE: How to unencode HTMLencoded strings ?

    HI,<BR><BR>Use javascript for form level validation. This prevents multiple roundtrips to the server, uses the browser as an intelligent tool to determine valid data, and prevents your problem discussed !<BR><BR>IQ

  3. #3
    Join Date
    Dec 1969

    Default RE: How to unencode HTMLencoded strings ?

    there&#039s no built in function in asp to do this, but this should help:<BR><BR>&#060;%<BR><BR>function UrlDecode(sData)<BR>if sData &#060;&#062; "" and instr(1,sData,"%",1) &#062; 0 then<BR>sData = replace(sData,"+"," ",1,1)<BR>loopi = instr(1,sData,"%",1)<BR>do while loopi &#062; 0<BR>sFind = mid(sData,loopi,3)<BR>For i = Len(replace(sFind,"%","",1,1)) To 1 Step -1<BR>iStep = 16 ^ ((Len(replace(sFind,"%","",1,1))) - i)<BR>If iStep = 0 Then iStep = 1<BR>i1 = Mid(replace(sFind,"%","",1,1), i, 1)<BR>If IsNumeric(i1) Then i1 = i1 * iStep Else i1 = (Asc(i1) + 10 - Asc("A")) * iStep<BR>fin = fin + i1<BR>Next<BR>sData = replace(sData,sFind,chr(fin),1,1)<BR>loopi = instr(1,sData,"%",1)<BR>loop<BR>UrlDecode = sData<BR>end if<BR>end function<BR><BR>response.write "&#060;textarea&#062;" & UrlDecode(request.form("formdata")) & "&#060;/textarea&#062;"<BR><BR><BR>%&#062;<BR><BR><BR>(Not e: I don&#039t claim this code to be my own, I beleive I found it somewhere and then modified it because it didn&#039t work correctly)

Posting Permissions

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