Question

I want to print my own dates in the form of variable in the URL:

I have the following url:

<cfset urladdress = "https://abc.xyz.com/start_date=2013-04-01&end_date=2014-04-22&data_type=123"> 

I have set my dates like the following:

<cfparam name="startdate" default="#DateFormat(dateAdd('d',-1,now()), 'yyyy-mm-dd')#">
<cfparam name="enddate" default="#DateFormat(dateAdd('d',0,now()), 'yyyy-mm-dd')#">

And now, I am trying to print it like the following:

<cfset urladdress = "https://abc.xyz.com/start_date="<cfoutput>#startdate#</cfoutput>"&end_date="<cfoutput>#enddate#</cfoutput>"&data_type=123">

And I get following error:

 Invalid CFML construct found on line 19 at column 123.
ColdFusion was looking at the following text:

<

The CFML compiler was processing:

    < marks the beginning of a ColdFusion tag.Did you mean LT or LTE?
    A cfset tag beginning on line 19, column 2.

Do I need to use URLEncoded Format Function ?

Was it helpful?

Solution

You don't need <cfoutput> inside a <cfset>

<cfset urladdress = 
  "https://abc.xyz.com/start_date=#startdate#&end_date=#enddate#&data_type=123">

You should use encodeForURL() (cf10+ only) or urlEncodedFormat() around the variables to be safe.

If you want to use encodeForURL() in CF9, check out: https://github.com/misterdai/cfbackport

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top