Array Notation vs. Evaluate()
While developing a web site for a customer, I recently had the problem with evaluating a form field to retrieve that field's value. For example:
I had a form field as follows:
As you can see I'm using a GUID in the name. This helps me map the form back to another entity after processing.
In order for me to get the value of the field, I loop through the fieldnames and Evaluate() that field as follows:
<cfset s.value = Evaluate("frm.#x#") />
</cfloop>
However, when I submit the form and run the code, I received this CF error:
The CFML compiler was processing: an expression beginning with "frm.q_1_f35d5381", on line 1, column 1.This message is usually caused by a problem in the expressions structure.
It looks like CF attempts to "subtract" the values between the "-" in the GUID. In other words, its attempting to subtract 4d404f55ed4c from 6332 which are the values at the end of my GUID.
After a few hours of attempting to resolve this issue I finally posted the issue on the Adobe Forums.
After just a half-hour a kind fellow by the name of Azadi (thanks Azadi, whoever you are) provided a fantastic solution: Array notation on the structure iteself instead of using evaluate! Duh.
I've used this solution before but not on a form structure. So, I changed the code that proceses the form as follows:
<cfif StructKeyExists(frm,"#x#")>
<cfset s.value = form['#x#'] />
</cfif>
</cfloop>
And it worked beautifully. Remember array notation instead of Evaluate() is a good option in this circumstance.

There are no comments for this entry.
[Add Comment]