[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Masking the & in a URL variable

Posted on 2006-03-21
3
Medium Priority
?
205 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>
0
Comment
Question by:tags266
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Renante Entera earned 2000 total points
ID: 16253680
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 :-)
0
 

Author Comment

by:tags266
ID: 16391561
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>
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 16397173
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 :-)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question