Skip to main content
Participant
May 26, 2006
Question

Passing a query string through the URL?

  • May 26, 2006
  • 2 replies
  • 338 views
Trying to pass a custom query string to a template through the URL, example (assume all inside cfoutput tags):

<cfset qrystr="name=Jane&eyes=brown&hair=blond&number=2125551234">
Here is the qrystr encoded: #URLEncodedFormat(qrystr)#<br>
<a href=" http://www.hfdkldf.com/main.cfm?action=saveinfo&qrystr=#URLEncodedFormat(qrystr)#">save her info</a>

Testing this out, I'm seeing that the second line's output indeed shows qrystr with "=" and "&" replaced by "%3D" and "%26", respectively. However, when I mouseover the link on line 3 and look at the URL in the status bar, I see the link's url does not have qrystr encoded. So, the receiving template is going to see qrystr only as "name=Jane", and not the full string. How can I pass qrystr in the URL so that it remains encoded and will be received with it's complete value?

I could use the replace function to custom encode qrystr myself, and then decode it at the receiving template, but I thought the whole point of a function like URLEncodedFormat was to avoid having to do that.
    This topic has been closed for replies.

    2 replies

    Inspiring
    May 26, 2006
    I'm pretty sure you want to use urlencodedformat in your cfset clause, on each string variable. Also, when you assemble your anchor tag, you don't want qrystring=#qrystr#, you just want

    <ahref="whereever?action=saveinfo&#qrystr#>

    Inside a cfoutput tag of course.
    cmmasoAuthor
    Participant
    May 26, 2006
    Thank you - I think it was a Firefox thing - even though the link looked decoded in the status bar, when I clicked on it, it was encoded in the address bar at the part I wanted encoded . And sure enough, looking at the debugging, it showed that url.action="saveinfo" and url.qrystr="name=Jane&eyes=brown&hair=blond&number=2125551234". In any event, I included URLEncodedFormat in my cfset clause as you suggested and that seemed to help.

    With building the anchor tag - good point, that's normally what I'd do, but I was considering how it would be done if I wanted to group all of those url vars inside a single url var instead of passing them "loose" as 4 separate url vars (sort of cheating to create a structure that can be passed via url).
    May 26, 2006
    You need CFOUTPUT wrapped around your link.