Passing variable into url

Discussion in 'Programming' started by chuck1rar, Aug 1, 2012.

  1. #1
    Am sure am missing something but why doesnt this work???
    If I hardcode the string value it works fine...

    <cfset Str_Order =#rsorder.order_id#>
    <cfoutput> #Str_Order# </cfoutput>
    <p><a href="MyAccount.cfm?view=customsinvoice&amp;OrderID=' #Str_Order# ' "> test</a></p>
     
    chuck1rar, Aug 1, 2012 IP
  2. wasistdas

    wasistdas Well-Known Member

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    Do this way:

    <cfset url.Str_Order =#rsorder.order_id#>

    <p><cfoutput><a href="MyAccount.cfm?view=customsinvoice&amp;OrderID=' #Str_Order# ' "> test</a></cfoutput></p>
     
    wasistdas, Aug 19, 2012 IP
  3. Aeromir

    Aeromir Active Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #3
    - You don't need the # symbols in your cfset statement
    - You can use cfparam instead of cfset if you're accepting a URL parameter to ensure the variable is always there and won't break your page
    - If your order_ID is numeric, you an check that with cfparam or use the val() function
    - Scoping your variables is always a good idea for speed and clarity
    - Your code looks like has extra spaces in the ordered you're generating. If your order_ID is non-numeric, you should make sure the string passed is URL encoded:

    
    [COLOR=#111111]<cfparam name="url.Str_Order" default="#rsorder.order_id#" />[/COLOR]
    <p>
      <cfoutput>
        [COLOR=#111111]<a href="MyAccount.cfm?view=customsinvoice&amp;OrderID=#urlencodedformat(url.Str_Order)#">test</a>[/COLOR]
      </cfoutput>
    </p>
    Code (markup):
     
    Aeromir, Aug 20, 2012 IP