How can I dynamically find what form fields have been posted into a page?

ColdFusion provides two easy ways to obtain a list of all form variables that have been posted to a page.

The first way is to use the form.fieldNames variable. The form.fieldNames variable is automatically available to any ColdFusion template that has received a form post and contains a comma-delimited list of form-field names that have been posted to the current template.

The second way is to use the form structure. The form structure is a special ColdFusion structure that contains each form-field name and its associated value. The following is a code sample for displaying the content of the form structure. Note how the form.fieldNames is filtered out of the result set:

<cfloop collection="#form#" item="theField">
<cfif theField is not "fieldNames">
<cfoutput>
#theField# = #form[theField]#<br>
</cfoutput>
</cfif>
</cfloop>

This question was written by Jeremy Petersen
It was last updated on April 17, 2006.

Categories

Forms

Comments

comments powered by Disqus