ColdFusion: Normalizing And Escaping Form Values

One way of normalizing and escaping your form fields is to loop through the list of FIELDNAMES as returned by the FORM scope (FORM.FIELDNAMES). This example escapes all form fields and trims each form field as well.

In this example we assume that the form has been submitted for processing.

<cfloop list="#FORM.FIELDNAMES#" index="i">
  <cfset FORM[i] = trim(htmlEditFormat(FORM[i]))>

You can obviously copy those sanitized values over to a new variable if you need to leave the original FORM scope untouched.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s