Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

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 at 7:00:55 AM EST.

CFML Referenced

<cfloop>

Categories

Forms

Comments

There are no comments for this entry.