Skip to main content
Inspiring
July 3, 2012
Answered

cflocation dropping characters

  • July 3, 2012
  • 1 reply
  • 769 views

Specifically it's dropping the ampersand "&" and all characters after this.

I  have a simple search form that sends the search item to an action page where depending on what variables are sent it either processes the form or sends the variable in the url to another page to get processed.

The form sends the variables correctly to the processing page. Using cfdump I see I'm getting the correct search item. Then I use cflocation to send the search item to a different page for processing but at this point on the third page the variable is missing anything behind the ampersand. "A&B" becomes "A"

My processing page looks like this.

<cfif IsDefined("form.how") and #form.how# eq "any">

     <cfset theitem = #trim(form.item)#>

<cflocation url="search.cfm?item=#theitem#" addtoken="no">

</cfif>

I receive "A&B" on this processing page but on the search.cfm page when dumping out the url variable I receive "A" and everything beyond and including the & is stripped.

I've tried setting the item variable as a session variable on the processing page but that didn't work either. I've tried using a meta refresh tag but got the same results. I've googled and do not see anything on this.

The "&" sign should be a valid character to search for in the database.

Any suggestions? thanks



This topic has been closed for replies.
Correct answer Adam Cameron.

Well... & has special meaning in a URL, doesn't it?  it's the separator between parameter name/value pairs.  So if you need it to be in your data (ie: the value of a parameter) you need to encode it so the web server KNOWS it's data and not part of the URL structure.

On CF10  use encodeForUrl():

http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WS932f2e4c7c04df8f-6f7941141353e2963af-7ffc.html

On previous versions use urlEncodedFormat():

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7bdf.html

--

Adam

1 reply

Adam Cameron.Correct answer
Inspiring
July 3, 2012

Well... & has special meaning in a URL, doesn't it?  it's the separator between parameter name/value pairs.  So if you need it to be in your data (ie: the value of a parameter) you need to encode it so the web server KNOWS it's data and not part of the URL structure.

On CF10  use encodeForUrl():

http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WS932f2e4c7c04df8f-6f7941141353e2963af-7ffc.html

On previous versions use urlEncodedFormat():

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7bdf.html

--

Adam

wam4Author
Inspiring
July 3, 2012

Doh!  Thank you. Sometimes the obvious get's overlooked. That should work.   Thank you for the reminder Adam.