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">
#theField# = #form[theField]#<br>

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




comments powered by Disqus