We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Masking the & in a URL variable

tags266
tags266 asked
on
Medium Priority
217 Views
Last Modified: 2013-12-24
My code is below...one of the records that shows up in my URL variable is the cable network A&E.  However the '&' is screwing up my search queries in my URL variable for 'networks'.  I'm sure this is an easy fix but if someone can point me in the right direction I'd be grateful.  Thanks

<cfif isdefined("form.submit") and form.submit EQ "Search Units">
<cflocation url="unit_search_results.cfm?city=#form.city#&subregion=#form.subregion#&network=#form.network#&timeslot=#form.timeslot#">
</cfif>
Comment
Watch Question

Senior PHP Developer
Commented:
Hi tags266!

In this case, you will have to use CF functions URLEncodedFormat() and URLDecode() to resolve your problem.

For your reference, simply visit the following :
  URLEncodedFormat - http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/funca114.htm#wp1114140
  URLDecode - http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/funca113.htm#wp1114097

So, the code will be like this :
------------------------------------------------------------------------------------------------------------------------------
<!--- use URLEncodedFormat() first before sending it as value of you url parameters --->
<cfif isdefined("form.submit") and form.submit EQ "Search Units">
  <cfset newCity = URLEncodedFormat(form.city)>
  <cfset newSubregion = URLEncodedFormat(form.subregion)>
  <cfset newNetwork = URLEncodedFormat(form.network)>
  <cfset newTimeslot = URLEncodedFormat(form.timeslot)>

  <cflocation url="unit_search_results.cfm?city=#newCity#&subregion=#newSubregion#&network=#newNetwork#&timeslot=#newTimeslot#">
</cfif>
------------------------------------------------------------------------------------------------------------------------------

Then, on your "unit_search_results.cfm" :
------------------------------------------------------------------------------------------------------------------------------
<!--- use URLDecode() first before using its value as condition(s) on your query statement --->
  <cfset newCity = URLDecode(url.newCity )>
  <cfset newSubregion = URLDecode(url.newSubregion )>
  <cfset newNetwork = URLDecode(url.newNetwork )>
  <cfset newTimeslot = URLDecode(url.newTimeslot )>

  <!--- Then your query statement will follow ... --->
------------------------------------------------------------------------------------------------------------------------------

I hope that this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks entrance..that's it.  sorry for the late points...i've increased them for you...just one thing was wrong with your <cflocation url which was confusing me...

This is what you wrote:
cflocation url="unit_search_results.cfm?city=#newCity#&subregion=#newSubregion#&network=#newNetwork#&timeslot=#newTimeslot#">
</cfif>


It should be:
cflocation url="unit_search_results.cfm?newcity=#newCity#&newsubregion=#newSubregion#&newnetwork=#newNetwork#&newtimeslot=#newTimeslot#">
</cfif>
Renante EnteraSenior PHP Developer

Commented:
Hi tags266!

I apologize for that minor mistake.  Anyway, I'm glad that you've seen it.

BTW, thanks for the points and grade. I'm glad that I have helped you.  Hope to help you again...


Regards!
eNTRANCE2002 :-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.