Coldfusion 8: IsDefined ('URL.variable') and not "?"?

I am trying to find out if the url variable exists, and if not, make sure it is not empty.

This does not work:

<cfif IsDefined('URL.affiliateId') and is not "">
    //
</cfif>
+5
source share
5 answers
<cfif structKeyExists(url, 'affiliateID') and trim(url.affiliateID) neq "">...</cfif>
+14
source

You can also simplify the logic by using <cfparam> so that the URL variable always exists. Then instead of having 2 conditions, you just need 1.

<cfparam name="URL.affiliateId" type="string" default="" />

<cfif trim( URL.affiliateId ) is not "">
     do stuff here
</cfif>
+4
source

<cfif IsDefined('URL.affiliateId') and len(trim(URL.affiliateId))>
    value is defined and not empty
</cfif>

...

<cfif IsDefined('URL.affiliateId') and len(trim(URL.affiliateId)) gt 0>
    value is defined and not empty
</cfif>
+1
<cfif IsDefined('URL.affiliateId') and URL.affiliateId neq "">
    //
</cfif>
0

:

<cfparam name="URL.affiliateId" type="string" default="" />

<cfif len(trim(URL.affiliateId))>
     ...do something with the affiliate...
</cfif>

structKeyExists isDefined, . " " "len()".

0

All Articles