House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Newbie (CF-Newbie)

alternatives to evaluate in cfloop

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Hi folks
Rob Voyle
04/04/12 09:43 P
Hi Ray
Rob Voyle
04/04/12 10:54 P
Hi Ray
Rob Voyle
04/04/12 11:20 P
Hi Ray
Rob Voyle
04/05/12 08:45 A
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Voyle
04/04/2012 09:43 PM

Hi folks I have a list of variables that I want to validate. <cfloop list="#list#"  index="variableNames" delimiters = ","> I can get it to work fine using evaluate. <cfif evaluate(variableNames) is ""> However most folks say evaluate is a performance hog and should be avoided. so what is the alternative? Thanks Rob

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
04/04/2012 09:46 PM

Evaluate isn't as slow as it used to be. That being said, you can use the Variable scope like a struct <cfif variables[variableName] is ""> ... ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Voyle
04/04/2012 10:54 PM

Hi Ray Here is the complete code. This validates form entries and creates an error message. this works fine I am just wanting to get rid of the "evaluate" <cfset variableNames=list=" workshopCode, workshopTitle, workshopTitleShort, workshopTitleEmail, workshopWeb, workshopInstructions "> <cfloop list="#variableNames#"  index="variableNames" delimiters = ","> <cfset trimVariable=reReplace(variableNames,chr(10),"", "all" )> <cfset trimVariable=reReplace(trimVariable,chr(13),"", "all" )> <cfset "error#trimVariable#"=""> <cfif evaluate(variableNames) is ""> <cfset "error#trimVariable#"= "<h5>This item can not be blank</h5>"> <cfset error="1"> </cfif> </cfloop> Thanks Rob

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Voyle
04/04/2012 11:20 PM

Hi Ray Still no go. Just to avoid confusuion I changed the index to items so I don't get confused with variable scope. <cfloop list="#variableNames#"  index="items" delimiters = ","> and then <cfif structKeyExists(form, items) and form[items] is ""> doesn't generate any appropriate error messages when an entry is ommitted. When I just use <cfif form[items] is ""> I get the scope error (same if I use variables[items] Thanks for you help on this. Rob On 4 Apr 2012 at 21:56, Raymond Camden wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andrew Scott
04/04/2012 11:26 PM

A good debugging technique here is to do this. <cfloop list="#variableNames#"  index="items" delimiters = ","> <cfoutput>#items#</cfoutput> Then you can see if that matches what you see in your form. And you get the error, in your second example, because it doesn't exist in the form scope. Which is why you need to do the strucyKeyExists, but I think you knew that. -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 On Thu, Apr 5, 2012 at 1:19 PM, Rob Voyle <robvoyle@voyle.com> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Voyle
04/05/2012 08:45 AM

Hi Ray I put in some data and left some elements blank which should trip the error message but they are not. cfdump yields BTNSUBMIT   Submit Workshop FIELDNAMES    VALIDATION,WORKSHOPCODE,WORKSHOPTITLE,WORKSHOPTITLESHORT,WORK SHOPTITLEALTERNATIVE,WORKSHOPTITLEEMAIL,WORKSHOPWEB,WORKSHOPA UDIO,WORKSHOPINSTRUCTIONS,BTNSUBMIT VALIDATION   2 WORKSHOPAUDIO   [empty string] WORKSHOPCODE   atm WORKSHOPINSTRUCTIONS   [empty string] WORKSHOPTITLE   Appreciative Transitional Ministry WORKSHOPTITLEALTERNATIVE   [empty string] WORKSHOPTITLEEMAIL   [empty string] WORKSHOPTITLESHORT   [empty string] WORKSHOPWEB   [empty string] On 5 Apr 2012 at 5:44, Raymond Camden wrote: ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search cf-newbie

May 25, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference