Need to use URL Encode in CFDiv Tag ColdFusion, receiving error

earwig75
earwig75 used Ask the Experts™
on
In the below tag, if the variable in the "bind" has a percent sign/url/special characters in it, it fails. I believe I need to encode/decode the variable thisVarBreaks, can someone assist?

on main page I have:
<cfdiv id="myDiv" bind="url:/site/name/myPage.cfm?myVariable=#thisVarBreaks#"/>

Open in new window


On the myPage.cfm I have:
<cfif someThing neq #URL.thisVarBreaks#>Hello</cfif>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Commented:
Looks like CF doesn't automatically encode special characters with bind:url, but wrapping the value in URLEncodedFormat should do the trick.

<cfdiv id="myDiv" bind="url:/site/name/myPage.cfm?myVariable="#URLEncodedFormat(thisVarBreaks)#"/>

Open in new window

Most Valuable Expert 2015

Commented:
Not sure how an extra quote sneaked into the above example, but ... for the archives, the correct code is:

<cfdiv id="myDiv" 
      bind="url:/myPage.cfm?myVariable=#URLEncodedFormat(thisVarBreaks)#"/>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial