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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i capture formating in a text area? 2

Status
Not open for further replies.

leadman

Programmer
Jun 11, 2001
177
0
0
US
Hi all,

I have a simple form that includes a textarea that users can uase to upload text to the database that will then be used in the body of a tempate. The textarea seems to capture all of the text except for any formating. For instance, one user tried to make a numbered list by using the enter key. It looked fine in the texarea on the form but after being saved to the database and being called to the page it just ran on withouth the formatting - like this:

*********what user put into textarea*************

1) This is my first point
2) This is my second point
3) This is my third point

***********what it looks like when output*********

1) This is my first point2) This is my second point3) This is my third point

**************************************************

Is there a way to capture formating like this?
 
What database and datatype are you using to store the field. I know that if you are using access then line breaks are not stored. If you use the memo type then line breaks are preserved.

Let me know how you get on.


Kola
 
I am using Access and the field type is memo - do i need to do anything to see the line breaks upon output?
 
I've done this before but I cant remember how.

Anyway 2 work arounds:

before saving to the database replace all new lines with
| then before displaying replace | wiht <br>

or before saving to the database replace all new lines with
| then display between <pre></pre> tags this preserves all new lines which I think being ignored ( as part of the html spec i think - white space is ignored)

this is the code i used to test it:

page1
<form action=&quot;test2.cfm&quot; method=&quot;post&quot;>
<textarea name=&quot;someField&quot;></textarea>
<input type=&quot;Submit&quot; >
</form>

page2
<cfset temp = replaceNocase(form.someField,&quot;#chr(13)##chr(10)#&quot;, &quot;|&quot; , &quot;all&quot; )>

<cfquery datasource=&quot;test&quot; >
insert into testTable1(someMemoField)
values('#temp#')

</cfquery>
<cfquery name=&quot;get&quot; datasource=&quot;test&quot; >
select * from testTable1
</cfquery>
<pre>
<cfset temp2 = replace(get.someMemoField, &quot;|&quot;, &quot;#chr(13)##chr(10)#&quot;, &quot;all&quot; )>
<cfoutput>#temp2#</cfoutput></pre>

HTH

Kola
 
Just thought about this again and really there is not point replacing newlines before inserting to the database. All you have to do is remember when displaying data entered into a text area save the field as a memo field and display between pre tags.

IF you're using CF5 which you should be you could write a really really simple UDF (not for performance but perhaps for readability):

<cfscript>
function preserveTextAreaFormat( textAreaInput ){
var output = &quot;<pre>#textAreaInput#</pre>&quot;;
return output;
}
</cfscript>

<cfoutput>#preserveTextAreaFormat(someQuery.someMemoField)#</cfoutput>
 
hmm - not using cf 5 yet. But using the <pre></pre> has helped - the returns are showing up - but now im not getting any word wrap and the lines not split up by returns are forcing the page out to twice the monitor size! Can I do anything about this? (the textarea that captured the text had wrap set to &quot;virtual&quot;, perhaps changing that would help?)
 
Here is something I found came in handy a couple of times...
to SHOW Carriage Returns and Line Breaks in Web Pages...
I think that MSAccess does enter some form of line breaks in memo fields.
Christine

<cfif IsDefined('FORM.address')>
<cfset address=&quot;#FORM.address#&quot;>
<cfset cr=Chr(13)&Chr(10)>
<cfset x=#Trim(Replace(address,cr,&quot;\r&quot;,&quot;ALL&quot;))#>
<cfset br= &quot;<br>&quot;>
<cfset x=#Trim(Replace(address,br,&quot;\r&quot;,&quot;ALL&quot;))#>
<cfset NewAddress = &quot;#x#&quot;>
</cfif>
 
I tried that code, Hautnueil, it comes out the same way though --- without <pre> tags it just runs on without any formatting, with <pre> tags it pays attention to carriage returns but doesnt automatically wrap! arrrgh!
 
I can be as simple as 1 line

<cfset form.myText = Replace(form.myText, Chr(13) & Chr(10), &quot;<br>&quot;, &quot;all&quot;)> - tleish
 
or you could just:

<CFLOOP List=&quot;#text#&quot; Index=&quot;rc&quot; Delimiters=&quot;#Chr(10)#&quot;>
#rc#<BR>
</CFLOOP>

Hope this helps

Ronald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top