Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problems saving/ displaying codes

Community Beginner ,
May 16, 2012 May 16, 2012

Hello,

I want to save html codes or any language code in my database.

For instance, am saving the text below in the database :

<!--- STRIP OUT ALL HTML --->

<cfset test = StripToHTML.stripHtml(VARIABLES.text, "all")>

<cfdump var="#test#"><br/>

<!--- STRIP OUT IMG, B, AND EM TAGS --->

<cfset test1 = StripToHTML.stripHtml(VARIABLES.text, "img,tag,false;b,tag,true;em,content,true")>

<cfdump var="#test1#"><br/>

When it has been saved in the database, it's like follows :

&lt;!--- STRIP OUT ALL HTML ---&gt;

&lt;cfset test = StripToHTML.stripHtml(VARIABLES.text, "all")&gt;

&lt;cfdump var="#test#"&gt;&lt;br/&gt;

 

&lt;!--- STRIP OUT IMG, B, AND EM TAGS ---&gt;

&lt;cfset test1 = StripToHTML.stripHtml(VARIABLES.text, "img,tag,false;b,tag,true;em,content,true")&gt;

&lt;cfdump var="#test1#"&gt;&lt;br/&gt;

And when I am displaying it on a page, it displayed as above.

Someone can tell me how to save the codes in the correct format in the database and how to make them display correctly ?

I am using MSSQL 2008 for the database.

753
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2012 May 16, 2012

Go to cflib.org and look for a function called safetext.  It will preserve benign tags and strip out dangerous ones.

Then, store the html exactly as you receive it.  Use safetext when you display it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2012 May 16, 2012
LATEST

well I have used the function safetext but unfortunately its not good.

I have test it with the test below :

Hello V/s <b>Hello</b>

and the result after using safetext qive me the result :

Hello  V/s &lt;b&gt;Hello&lt;/b&gt;

I have already do a rereplace function to replace the &lt; and &gt; with <> but this would appear like :

Hello  V/s Hello

Instead of showing the tag b , it execute the html tag.

I don't know how to make any codes appear on a page.

Could anyone please help me ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2012 May 16, 2012

So you don't want to strip it out, you want to escape it?

Would htmlEditFormat() do the trick?  Or if you're on CF10 (which, admittedly, is doubtful ;-), encodeForHtml()?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2012 May 16, 2012

htmlEditFormat() don't do the trick and am using coldfusion 9 so can't use the encodeforhtml.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources