Posted By

nehringryan on 05/09/11


Tagged

ColdFusion


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dreamstarter
Priestd09


Auto Trim/Clean Submitted Form Data in Coldfusion


 / Published in: ColdFusion
 

URL: http://ryannehring.com/

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.

  1. <cfloop collection= "#form#" item="formfield" >
  2. <cfset form[formfield] = trim(htmlEditFormat(form[formfield]))>
  3. </cfloop>

Report this snippet  

You need to login to post a comment.