April 1, 2006

How do I trim the contents of a form?

From ColdFusion Cookbook:

Trimming is an essential part of dealing with an data coming from form textfields or textareas etc. You can of couse trim as and when you need (before validation or database inserts etc) but if you can trim all fields quickly and easily!

<cfloop collection="#form#" item="formfield">
    <cfset form[formfield] = trim(form[formfield]) />
</cfloop>

This basically loops over a form structure and trims each element. You can use this loop in a function before handing it to your validation or database methods.

Read the full article

© Michael Sharman 2017