Not yet rated

Problem

So, you need to scrub out a lot of the hidden crap from text area fields where Word documnets have been copied and pasted into them? We have a custom tag for that!

Solution

A little CF Custom Tag can do the trick. It's simple and easy to edit and use - and you can easily modify or improve it as you go.

Detailed explanation

<!---
cf_scrubber (scrubber.cfm) custom tag
This custom tag scrubbs a lot of garbage out of cust and paste,
especially out of Word documents.  This is a work in process.

Use as such:
 <cf_scrubber fieldName="{form field name here}">
 
(output from tag)
 #request.{form field name here}#

You can pass it a comma delimited list of field names, so one call
to the custom tag can scrub as many fields at a time as you need.

Data is passed back to your script in a "REQUEST" socpe variable
of the same name as your form field name.

ex: <cf_scrubber fieldName="firstName,lastName,middleName">
ex: returns:  request.firstName;  request.lastName;  request.middleName

This example - scrubbs the following:
 -- hard returns (converts to <p>)
 -- left & right double quotes
 -- single quotes
 -- left & right brackets
 --->

<cfset newMsg = "">
<cfset field = Attributes.fieldName>
<cfloop index="z" list="#field#">
 <cfset newMsg = "">
 <cfloop index="i" list="#evaluate("form." & z)#" delimiters="#chr(32)#">
  <cfset temp = replace(i, chr(8220), """", "all")>
  <cfset temp = replace(temp, chr(8221), """", "all")>
  <cfset temp = replace(temp, chr(8216), "''", "all")>
  <cfset temp = replace(temp, chr(60), "&lt;", "all")>
  <cfset temp = replace(temp, chr(62), "&gt;", "all")>
  <cfset temp = replace(temp, chr(13), "<p>", "all")>
  <cfset newMsg = listAppend(newMsg, temp, "#chr(32)#")>
 </cfloop>
 <cfset "request.#z#" = newMsg>
</cfloop>


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes