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]))>
</cfloop>

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s