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!

What does evaluate mean, and where is an example?... 2

Status
Not open for further replies.

happyb

Programmer
Oct 25, 2000
29
AU
Hi,

I am not understanding the evaluate(Stringexpr) function. Can anyone decribe it, or send me to a page with a functional example? I am reading this CF book, and it is not very good. It shows you code examples... but it doesn't show you the result.

Thanks
happy :)
 
I've never used it, but I believe it's for evaluating a string expression. The book I have gives the following example:

"The string "1+2" contains an expression that, when evaluated, returns 3.

So, I guess if you had a variable that was like:
Code:
<CFSET myExpression = &quot;1+2&quot;>
<CFOUTPUT>#Evaluate(&quot;myExpression&quot;)#</CFOUTPUT>

You'd get &quot;3&quot;

If anyone has a more detailed example, or better yet, a really good use for this function, I'd like to hear about it. Kevin
slanek@ssd.fsi.com
 
You can use Evaluate when you're using dynamic variable names. For example: Say you have a page that processes a form but the variable names on the form are not known. The variable FORM.Fieldnames contains a list of all the fields on the submitted form. You could, for example, loop through all the fields on the form and output them to the screen:

<cfloop index=&quot;FormFieldName&quot; list=&quot;#FORM.Fieldnames#&quot;>
<cfset FormFieldName = &quot;FORM.&quot; &amp; Variables.FormFieldName>
<cfoutput>
#Variables.FormFieldName#: #Evaluate(Variables.FormFieldName)#<br>
</cfoutput>
</cfloop>

This will effectively display all the fieldnames and their values in the pages output. Try copying this code and testing it with a form that you have! Andrew
amayer@sonic.net
 
I see. Thanks Andrew.

Tell me this, because I'm having a hard time picturing it. Why might you have a form with variable field names? I'm sure the answer will be like a slap in the head, but at the moment I can't come up with a reason. (duh.....) Kevin
slanek@ssd.fsi.com
 
I don't know off hand. :-I It just seemed like a good example. I guess you could write your own mail form tag using that code. Andrew
amayer@sonic.net
 
Very intuitive. Thanks again for the info. Kevin
slanek@ssd.fsi.com
 
happyb,
Sorry for the late response to your question...but just found the site....

ColdFusion only knows about variables defined within itself, it does not know about
pseudovariables.

Whenever you send a value from a Form via the SUBMIT which uses a dynamic
name for its itdentifier you generally would call it up via the #form.variable#.

However, when using dynamic fields you may use an incrementing naming scheme for each field; i.e., book_name_1, book_name_2, book_name_3, etc. The number of these would be based upon existing Table entries.

If you knew the exact name being selected by the client you could then call it up on the Action page side as: ie, book_name_2. However on the Action Page side you must
test for each via a loop. looping the i value:
you would generate i = 1 through x (use proper loop format)
<cfset dog = 'form.book_name_' &amp; 'i'>
<cfif isdefined(#dog#)>
(((((action)))))))))
<cfif>
Now you can find out which item was selected and its value. However, CF
doesn't recognize #dog# as a valid variable for 'form.book_name_2' in this case.
And that is where EVALUATE enters.
You can now enter:
<cfset bookvalue = #evaluate(dog)#> (((note # on outside of evaluate)))
Now CF knows that BOOKVALUE is a CF variable and it also can acquire its value.

Hope that wasn't too confusing.

pjbarteck

 
Kevin,
We used the evaluate function on dynamically created
forms that had variables as form names. We had to do this
because the forms were generated based upon custom templates designed by the user. Question, Question Type, answer, etc. info was stored in the db. We then need to use the evaluate function to retrieve the form fields once
it was submitted.

jnl
 
jnl,
It's funny you should say that. Since this thread was created, I have used the evaluate() function for the exact same purpose. The field names of several text boxes I was using were actually variables, and I used evaluate() to output those user inputs.

Thanks though.
Kevin
slanek@ssd.fsi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top