ColdFusion CustomTags

Safe Text

<!--- Blocks the display of HTML and white space that is located outside of cfoutput tags. --->
<CFSETTING ENABLECFOUTPUTONLY="Yes">
<cfparam name="Attributes.safe_text" type="string">
<!--- Define list of "bad" characters --->
<CFSET bad_chars="&,<,>,"",Æ,Á,Â,À,Å,Ã,Ä,Ç,Ð,É,Ê,È,Ë,Í,Î,Ì,Ï,Ñ,Ó,Ô,Ò,Ø,Õ,Ö,Þ,Ú,Û,Ù,Ü,Ý,
á,â,æ,à,å,ã,ä,ç,éê,è,ð,ë,í,î,ì,ï,ñ,ó,ô,ò,ø,õ,ö,ß,þ,ú,û,ù,ü,ý,ÿ,¡,£,¤,
¥,¦,§,¨,©,ª,«,¬,­,®,¯,°,±,²,³,´,µ,¶,·,¸,¹,º,»,¼,½,¾,¿,×,÷,¢">
<!--- Define list of "good" characters --->
<CFSET good_chars="&amp;,&lt;,&gt;,&quot;,&AElig;,&Aacute;,&Acirc;,&Agrave;
,&Aring;,&Atilde;,&Auml;,&Ccedil;,&ETH;,&Eacute;,&Ecirc;,&Egrave;,&Euml;,&Iacute;,
&Icirc;,&Igrave;,&Iuml;,&Ntilde;,&Oacute;,&Ocirc;,&Ograve;,&Oslash;,&Otilde;,&Ouml;,
&THORN;,&Uacute;,&Ucirc;,&Ugrave;,&Uuml;,&Yacute;,&aacute;,&acirc;,&aelig;,
&agrave;,&aring;,&atilde;,&auml;,&ccedil;,&eacute;,&ecirc;,&egrave;,&eth;,&euml;
,&iacute;,&icirc;,&igrave;,&iuml;,&ntilde;,&oacute;,&ocirc;,&ograve;,&oslash;,&otilde;,
&ouml;,&szlig;,&thorn;,&uacute;,&ucirc;,&ugrave;,&uuml;,&yacute;,&yuml;,&iexcl;,
&pound;,&curren;,&yen;,&brvbar;,&sect;,&uml;,&copy;,&ordf;,&laquo;,&not;,&shy;,
&reg;,&macr;,&deg;,&plusmn;,&sup2;,&sup3;,&acute;&micro;,&para;,&middot;,
&cedil;,&sup1;,&ordm;,&raquo;,&frac14;,&frac12;,&frac34;,&iquest;,&times;,&divide;,&cent;">
<CFSET caller.safe_content=ReplaceList(Attributes.safe_text, bad_chars, good_chars)>
<CFSETTING ENABLECFOUTPUTONLY="No">Check if a string contains HTML code. Tag example:

<cfset content = "">
<form name="test" method="post" action="safe_txt_out.cfm">
<textarea name="txt" cols="40" rows="5"><cfoutput>#content#</cfoutput></textarea><br>
<input name="Submit" type="submit">
</form>

<cfmodule template="safe_text.cfm"
safe_text = "#Form.txt#" >

<cfoutput>#safe_content#</cfoutput>

ScandicWeb is own by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.