Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<cfset post =paragraphformat(post)>???

Status
Not open for further replies.

peter11

Instructor
Joined
Mar 16, 2001
Messages
334
Location
US
I am trying to allow for users to create <br> when they hit the enter key while typing in a Textarea.

I tried the following:

<cfset post=paragraphformat(post)>
This returned an Cold fusion Error on post=paragraphformat(post)

<cfset post=relacelist(post,&quot;#chr(13)#, <, >, #chr(34)#, #chr(39)#, #chr(35)#, #chr(38)#, #chr(47)#&quot;, , &quot;<br>, &lt;, &gt;, &quot;, &acute;, &#35;, &#38;, &#47;&quot;, &quot;all&quot;>
This returned multiple errors.

Does anyone know what the problem is with these?

Thanks

 
first, you have few typos in there;
second, when you want to have double quote as a part of the string, you have to escape them by repeating them (set i = &quot;&quot;&quot; wil give you error; set i = &quot;&quot;&quot;&quot; where i is &quot;);
third, you can't scope ReplaceList() function with &quot;one&quot; or &quot;all&quot; - it does not support that; you might want to use loop to check for characters you want to replace and then if char is found, use Replace() which you CAN scope with &quot;all&quot;

I haven't test the following code, but this should give you an idea as what I am suggesting:

<cfset replaceList = &quot;#chr(13)#, <, >, #chr(34)#, #chr(39)#, #chr(35)#, #chr(38)#, #chr(47)#&quot;>
<cfset replaceChars = &quot;<br>, <, >, &quot;&quot;, ``, #, &, /&quot;>

<cfset counter = 1>
<cfloop index=&quot;replaceCounter&quot; list=&quot;replaceList&quot; delimiters=&quot;,&quot;>
<cfset char = Find(replaceCounter, post)>
<cfif char GT 0>
<cfset post = Replace(post, replaceCounter, ListGetAt(), &quot;all&quot;)>
</cfif>
<cfset counter = counter + 1>
</cfloop> Sylvano
dsylvano@hotmail.com
 
Sylvano,
Do you know where I could get a book or more information on this topic?

Peter
 
I tried the following code and it got hung up at the comma after the #after ``, on the third line of code.

I removed that section of code from the second and third line of code and the code then hung up at <cfset char = Find(replaceCounter, post)>, on the eigth line of code.

The worst part is I really do not understand this code. Can anyone solve this problem or tell me where I can reasearch this topic.

<cfset replaceList = &quot;#chr(13)#, <, >, #chr(34)#, #chr(39)#, #chr(35)#, #chr(38)#, #chr(47)#&quot;>
<cfset replaceChars = &quot;<br>, <, >, &quot;&quot;, ``, #, &, /&quot;>

<cfset counter = 1>
<cfloop index=&quot;replaceCounter&quot; list=&quot;replaceList&quot; delimiters=&quot;,&quot;>
<cfset char = Find(replaceCounter, post)>
<cfif char GT 0>
<cfset post = Replace(post, replaceCounter, ListGetAt(), &quot;all&quot;)>
</cfif>
<cfset counter = counter + 1>
</cfloop>
 
I don't see why you'd get an error with. What is the error?
<CFSET post = ParagraphFormat(post)>

Here the fixes to the other code.
<CFSET post = ReplaceList(post, &quot;#chr(10)#, <, >, #chr(34)#, #chr(39)#, #chr(35)#, #chr(38)#, #chr(47)#&quot;, &quot;<br>, <, >, &quot;&quot;, ´, ##, &, /&quot;)>


What is it you are exactly trying to accomplish here? - tleish
 
Sylvano -Thanks

Tleish -I want the database to store the information the user enters and reproduce it exactly as it was entered, with the same charaters, carriage returns. And to display html tags, not apply the tags to the other text they entered.
 

<CFSET post = '[COLOR=000080]<i>[/color]This[COLOR=000080]</i>[/color]

[COLOR=000080]<b>[/color]is[COLOR=000080]</b>[/color] a
&quot;Quote&quot;
test'>


<CFSCRIPT>
[COLOR=666666]// Escape Special HTML Characters[/color]
post1 = HTMLEditFormat(post);

[COLOR=666666]/* Format spaces, tabs, and returns instead of this step
you could simply put the text in <PRE></PRE> tags and
it will display the proper format of tabs, spaces,
and returns which makes cleaner source

SPACES: There's no need to replace every space with a
no-break-space, just every 2 Replace 2 spaces
&quot;#Chr(32)##Chr(32)#&quot; with 2 no-break-space
&quot;&nbsp;&nbsp;&quot;

TABS: To force tabs we need to replace every tab
with 8 no-break-space Replace 1 tab &quot;#Chr(9)#&quot;
with 8 no-break-space &quot;#RepeatString('&nbsp;', 8)#&quot;

RETURNS: To force HTML returns we replace all carriage
returns #Chr(10)# with <BR> and to format the
code correctly we still keep our carriage returns
#Chr(10)#, otherwise it becomes one big string.
Replace 1 return &quot;#Chr(10)#&quot; with &quot;<BR>#Chr(10)#&quot;

*/
[/color]

post2 = ReplaceList(post1, &quot;#Chr(32)##Chr(32)#,#Chr(9)#,#Chr(10)#&quot;, &quot;&nbsp;&nbsp;,#RepeatString('&nbsp;', 8)#,<BR>#Chr(10)#&quot;);
</CFSCRIPT>


[COLOR=666666]<!--- Examples of Output --->[/color]
<CFOUTPUT>
Output [COLOR=000080]<B>[/color]post1[COLOR=000080]</B>[/color] to the page:[COLOR=000080]<BR>[/color][COLOR=000080]<BR>[/color]

[COLOR=000080]<PRE>[/color]#post1#[COLOR=000080]</PRE>[/color]

[COLOR=000080]<B>[/color]Actual Source:[COLOR=000080]</B>[/color]
[COLOR=000080]<PRE>[/color]#HTMLEditFormat(post1)#[COLOR=000080]</PRE>[/color]

[COLOR=000080]<BR>[/color][COLOR=000080]<BR>[/color]

Output [COLOR=000080]<B>[/color]post2[COLOR=000080]</B>[/color] to the page:[COLOR=000080]<BR>[/color][COLOR=000080]<BR>[/color]

#post2#[COLOR=000080]<BR>[/color]

[COLOR=000080]<B>[/color]Actual Source:[COLOR=000080]</B>[/color]
[COLOR=000080]<PRE>[/color]#HTMLEditFormat(post2)#[COLOR=000080]</PRE>[/color]

</CFOUTPUT> - tleish
 
That last post should have & nbsp; (withouth the space between &quot;&&quot; and &quot;nbsp;&quot;) instead of spaces, but cftips is interpreting it as spaces


post2 = ReplaceList(post1, &quot;#Chr(32)##Chr(32)#,#Chr(9)#,#Chr(10)#&quot;, &quot;& nbsp;& nbsp;,#RepeatString('& nbsp;', 8)#,<BR>#Chr(10)#&quot;); - tleish
 
tleish -
Thanks.
That worked perfect, but I do not really understand how it works.
Can you tell me where I can learn more about this. Are there any textbooks or books I can get?

Thanks for the great help

Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top