Auto Trim/Clean Submitted Form Data in Coldfusion

/ Published in: ColdFusion
Save to your folder(s)

A lot of people forget that the FORM scope is just a structure, and as such can be manipulated in all the same ways any other Struct could be... including looping through it with a cfloop collection... below is an example of code you could have at the top of a CFM action page or in a CFC Function to strip out any whitespace/invalid letters from a forms values before using them.

This collection cfloop performs native coldfusion functions htmlEditFormat and trim on each value from the form struct before saving the clean variable back to form.

Copy this code and paste it in your HTML
  1. <cfloop collection= "#form#" item="formfield" >
  2. <cfset form[formfield] = trim(htmlEditFormat(form[formfield]))>
  3. </cfloop>


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.