Inputing HTML in text area and being able to display the code without the HTML working on the page

Hi experts,

I'm trying to  create a page in Coldfusion that inputs HTML code and displays it as text, something similar to how this experts-exchange forum works, so I don't want the HTML to actually change anything on the page but I want to be able to display it.

So my question is how do I go about doing this? I'm assuming we need to use something like HTMLCodeFormat to convert symbols to the HTML characters so they can be inputed into the database easily (I'm using access) but then how do u display them without turning it into actual HTML on the page?!
techman36Asked:
Who is Participating?
 
Scott BennettConnect With a Mentor Manager TechnologyCommented:
you can use HTMLCodeFormat to replace the html characters before you enter it into the database. Then when you pull it out of the database and display it, you would just output it as is as it is already html escaped and surrounded by <pre></pre> tags
0
 
James RodgersWeb Applications DeveloperCommented:
a beeter option is #htmlEditFormat(thisFile,-1)# escapes teh special char in html (<,>,%,' etc) and preserves formatting

i use this in a text area to edit text based pages (txt, cfm, html, etc) online
read file contents into a variable
<cffile action="read" file="#url.pth#\#URL.file#" variable="thisFile">
display as editable text
<textarea name="fileContent" style="font-family:verdana; font-size:11px; height:500px; width:600px;">#htmlEditFormat(thisFile,-1)#</textarea>
0
 
Scott BennettManager TechnologyCommented:
If you are going to put the code in a textarea box then you should use htmlEditFormat as jester suggests but from your question it seems like you want to just display it inline with the forum text as EE does. In this case I would recomend using HTMLCodeFormat
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
techman36Author Commented:
Ok so HTMLCodeFormat sounds great the only issue is that I want to allow the user to update their inputs, when I repopulate the text area so the user can edit their inputs, the <PRE> and </PRE> tags apear around the data. How do I remove these from both ends? Any simple way to do this?!
0
 
James RodgersWeb Applications DeveloperCommented:
thats why i suggested the #htmlEditFormat(thisFile,-1)# option, the reason i use this is to avoid the <pre> tag being constanly appended to the file
0
 
Scott BennettManager TechnologyCommented:
oh ok if you are going to allow them to edit their posts, then use htmleditformat when you put it into the database, then surround each post by <pre> tags when you want to display it and don't use them when you want to edit it in a textarea field.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.