Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unusual CFIF exception error

Status
Not open for further replies.

deepatpaul

Programmer
Jul 7, 2004
57
US
For some reason, the CFIF inside this loop throws me an error when using the evaluate() function, which is wierd. I've done this a million times before; the list being passed is valid (as is the scope) and just outputting #len(evaluate("variables.#variables.ThisFieldName#"))# renders me the correct value. So, why on earth would it fail inside this IF?

<cfloop index="variables.ThisFieldName" list="#variables.CantBeBlankFieldList#">
<!--- Determine if the field has any data... --->
<cfif len(evaluate("variables.#variables.ThisFieldName#")) is 0>
<cfoutput>#variables.ThisFieldName# is invalid.<br></cfoutput>
</cfif>
</cfloop>

Template Exception - in C:\cfroot\includes\validate_input_cust.cfm : line 115

Invalid CFML construct found on line 1 at column 24
 
Code:
<cfloop index="variables[red].[/red]ThisFieldName" list="#variables.CantBeBlankFieldList#">
    <!--- Determine if the field has any data... --->
    <cfif len(evaluate("variables.#variables.ThisFieldName#")) is 0>
    <cfoutput>#variables.ThisFieldName# is invalid.<br></cfoutput>
    </cfif>
</cfloop>

As I'd thought, so I counted in to find out... your error is on line at the red "."...

Try this

Code:
<cfloop index="fldName" list="#variables.CantBeBlankFieldList#">
    <!--- Determine if the field has any data... --->
    <cfif len(evaluate("variables." & fldName)) is 0>
    <cfoutput>#fldName# is invalid.<br></cfoutput>
    </cfif>
</cfloop>

For fun though... try this... If it works, its better code.

Code:
<cfloop index="fldName" list="#variables.CantBeBlankFieldList#">
    <!--- Determine if the field has any data... --->
    <cfif len(variables[fldName]) is 0>
    <cfoutput>#fldName# is invalid.<br></cfoutput>
    </cfif>
</cfloop>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Your first alternative produced the same error I was getting, however, your 2nd solution works great (with some tweaking of other code for it to function. Thank you so much!

What is the reason for the IF failure on the first 2 options above? Even without the scope as part of the index's variable name, it still craps out. Evaluate() inside of IF's isn't that unusual.
 
Its not the cfif that's tripping, its the index attribute of the cfloop. You can't assign a scope to it. Its just a very very local variable.

Of the three sets of codes, btw, the first is an exact copy of yours.. I just highlighted the . in the index attribute. Hard to see though.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
I noticed that your 1st solution was an exact copy of mine, minus the 'variable.', but it was still throwing that error, which was stumping me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top