How do I trim the contents of a form?
This piece of code will trim the contents of a form. Since the form scope always exists in ColdFusion, you can either run it automatically, or only when a form post is submitted.
<cfloop collection="#form#" item="formfield">
<cfset form[formfield] = trim(form[formfield])>
</cfloop>
Another suggestion would be to htmlEditFormat the data. This escapes any HTML tags the user may have entered into the form:
<cfloop collection="#form#" item="formfield">
<cfset form[formfield] = trim(htmlEditFormat(form[formfield]))>
</cfloop>
This question was written by Tjarko Rikkerink
It was last updated on January 13, 2006.