View Single Post
  #13 (permalink)  
Old 02-18-2008, 10:00 PM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,321
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Decoding form fields

Decoding form fields


If you are using a version of Cold Fusion prior to 4.5, you may encounter a small glitch where a form field is not decoded when your program runs. For example, %20 is not replaced with a space. This normally occures when you pass hidden form fields where the value was encoded with the URLEncodedFormat function.

The code below will take a variable and replace all escaped characters with the actual character.

Example HTML/CFML code:

Code:
<CFSET str=result>
<CFSET ck=0>
<CFLOOP CONDITION="ck EQUAL 0">
  <CFSET loc=Find("%",str)>
  <CFIF loc EQUAL 0>
    <CFSET ck=1>
  <CFELSE>
    <CFIF Mid(str,loc,3) EQUAL "%25">
      <CFSET loc=Find("%",str,loc+1)>
      <CFIF loc EQUAL 0>
        <CFSET ck=1>
      <CFELSE>
        <CFSET str=Replace(str,Mid(str,loc,3),Chr(InputBaseN(Mid(str,loc + 1,2),16)),"ALL")>
      </CFIF>
    <CFELSE>
      <CFSET str=Replace(str,Mid(str,loc,3),Chr(InputBaseN(Mid(str,loc + 1,2),16)),"ALL")>
    </CFIF>
  </CFIF>
</CFLOOP>
<CFSET str=Replace(str,"+"," ","ALL")>
<CFSET str=Replace(str,"%25","%","ALL")>
<CFOUTPUT>#str#</CFOUTPUT>
__________________
Prasanna Vignesh
MCPD | Web Developer
Reply With Quote