|
Mailing Lists
|
Home /
Groups /
ColdFusion Newbie (CF-Newbie)
alternatives to evaluate in cfloop
Author: Rob Voyle
Short Link: http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:1335#5848
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 -----
Author: Andrew Scott
Short Link: http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:1335#5847
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 -----
Author: Rob Voyle
Short Link: http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:1335#5846
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 -----
Author: Rob Voyle
Short Link: http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:1335#5845
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
Author: Raymond Camden
Short Link: http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:1335#5844
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 -----
Author: Rob Voyle
Short Link: http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:1335#5843
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
|
May 22, 2013
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||