#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    60
    Rep Power
    4

    URL encodedFormat


    Hi Peers,

    i'am trying to pass a URL "encodedFormat" string to another page.
    I'am having trouble to pass symbols like # otherwise everything else seem to work.

    source page

    Code:
    <cfset var1="abc$d"> 
    <cflocation url="URLDECODE.cfm?var11=#urlEncodedFormat(var1)#">

    destination page

    Code:
    <cfoutput> 
    The url variable passed is : #URL.var11# </cfoutput>
    if i put var1="abc12#", this will gimme an error ...

    problem happens only with # symbol

    Thoughts
    Last edited by korssane; January 10th, 2012 at 05:47 PM.
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,265
    Rep Power
    968
    <cfset var1="abc$d">
    <cfset encodedVar1 = URLEncodedFormat( var1 ) />
    <cflocation url="URLDECODE.cfm var11=#encodedVar1#">
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    60
    Rep Power
    4
    Originally Posted by kiteless
    <cfset var1="abc$d">
    <cfset encodedVar1 = URLEncodedFormat( var1 ) />
    <cflocation url="URLDECODE.cfm var11=#encodedVar1#">

    Hi Kiteless,
    this does not work for me. iam trying to pass "abc$d#" ..it seems not accepting the # sign..

    error :

    Invalid CFML construct found on line 20 at column 18.

    ColdFusion was looking at the following text:
    URLDECODE.cfm

    The CFML compiler was processing:

    An expression that began on line 18, column 19.
    The expression might be missing an ending #, for example, #expr instead of #expr#.
    An expression beginning with \", on line 18, column 13.This message is usually caused by a problem in the expressions structure.
    A cfset tag beginning on line 18, column 2.

    The error occurred in C:\ColdFusion9\wwwroot\URLENCODE.cfm: line 20
    18 : <cfset var1="abc$d#">
    19 : <cfset encodedVar1 = URLEncodedFormat( var1 ) />
    20 : <cflocation url="URLDECODE.cfm var11=#encodedVar1#">
    21 :
    22 :
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,265
    Rep Power
    968
    Try escaping the pound sign:

    <cfset var1="abc$d##">
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    60
    Rep Power
    4
    Originally Posted by kiteless
    Try escaping the pound sign:

    <cfset var1="abc$d##">
    Hi Kiteless, i got that but how if i have a text field value that contains # pound sign and want to pass in URL ?


    thanks
  10. #6
  11. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,265
    Rep Power
    968
    It should work fine, I'm pretty sure you only have to escape pound signs you declare in CF code.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    60
    Rep Power
    4
    Originally Posted by kiteless
    It should work fine, I'm pretty sure you only have to escape pound signs you declare in CF code.
    hi kiteless,
    it is not clear. i'am assuming that the user might enter a pound sign in a text field and then i try to pass it ..
    thanks
  14. #8
  15. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,265
    Rep Power
    968
    If you declare a pound sign in CFML code, you must escape it because the pound sign has special meaning in CFML code. If the value is passed in from outside the code, you don't have to escape it.

    Just build a simple form, open it in your browser, and test it.

IMN logo majestic logo threadwatch logo seochat tools logo