Daemon

 
Home / Services / Adobe Training / Tips & Tricks

Handling Form Variables Dynamically - Part Two

uthor: Andrew Muller

"Fieldnames" a comma-separated list that is created as an additional variable in the form scope for every form submitted. It contains a list of the form control names from the form.

Since we are able to loop over lists this is a good starting point for a way to handle form variables dynamically on the action page.

"i" list="#form.fieldnames#">

#i#
 

We are using a list loop in our sample code with the variable form.fieldnames as our list. The index attribute of CFLOOP is a variable that is used to reference the next element of the list.

Screenshot 1
Screenshot 1

If we place this code on our action page we should see that the resulting output would be the fieldnames, to display the values of each of these variables we shall have to add more code.

"i" list="#form.fieldnames#">

#i#: #evaluate("form.#i#")#


Screenshot 2
Screenshot 2

Here we have used the function "evaluate" to dynamically resolve the value of the form variable. This function is used to evaluate arguments and return the result and is more commonly used for math.

At runtime the hashes around "i" will print the value of the variable into the string being used within the function so that it can return the result of it's evaluation of the string. It helps to think of this process in two steps:

  1. The hashes print the value so that the code becomes:

#evaluate("form.FirstName")#

  1. Evaluate then evaluates the string to determine it's value.

While looping over the "fieldnames" appears to handle the form variables successfully it doesn't address the problem solved using CFPARAM that we discovered in part one. CFPARAM inserts a new value in the form scope which is quite separate to the "fieldnames" list.

We shall address and complete this series in part three

Menu

Social Profiles