Link to home
Start Free TrialLog in
Avatar of techman36
techman36

asked on

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?!
ASKER CERTIFIED SOLUTION
Avatar of Scott Bennett
Scott Bennett
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>
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
Avatar of techman36
techman36

ASKER

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?!
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
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.