ColdFusion

formatting text

Page 1 of 1

2 Replies - 3023 Views - Last Post: 08 April 2010 - 06:51 AM Rate Topic: -----

#1 Guest_S.Griffin*


Reputation:

ColdFusion

Posted 08 April 2010 - 05:53 AM

Sup my people. I have a simple CF question about text formatting. In PHP you can use nl2br($text) to keep the line break and returns for text entered in the DB (blog, longtext, etc). I was trying to find the equivalent in CF but have not been able to. Could someone provide some guidance for me.

Thank
Griff
Is This A Good Question/Topic? 0

Replies To: ColdFusion

#2 Guest_S.Griffin*


Reputation:

Re: ColdFusion

Posted 08 April 2010 - 06:47 AM

Alright party people. I found a solution this issue. I found that I can use the ParagraphFormat() function to format the text for me. My bigger problem was using FCKEditor on a CF7 server. the variable was not being sent to the DB when updating.

This is what i started with.
----Form user see's----
<cfquery name="get_inspections" datasource="#db#">
select id,inspection
from IG_INSPECTIONS
</cfquery>

<cfform action="tester_update.cfm" enctype="multipart/form-data" method="post">
<cfoutput query="get_inspections">

<cfmodule template="/occ/fckeditor/fckeditor.cfm"
basepath="/occ/fckeditor/"
instanceName="editor"
width="465"
height="200"
value='#get_inspections.inspection#'
ToolbarSet="LaToya">
</cfoutput>
<cfinput name="update" type="submit" value="Update" />
</cfform>

---processing cfm file------

<cfquery name="update_tester" datasource="#db#">
update ig_inspections
set inspection = '#editor#'
</cfquery>
<cflocation url="tester.cfm">

The value was not being passed.

I changed it the user form to:

<cfform action="tester_update.cfm" enctype="multipart/form-data" method="post">
<cfoutput query="get_inspections">

<cfmodule template="/occ/fckeditor/fckeditor.cfm"
basepath="/occ/fckeditor/"
instanceName="editor"
width="465"
height="200"
value='#ParagraphFormat(get_inspections.inspection)#'
ToolbarSet="LaToya">
</cfoutput>
<cfinput name="update" type="submit" value="Update" />
</cfform>

Added the ParagraphFormat() to the value attribute of the cfmodule and the updated value was passed to the DB.

--I know we should be on CF 8 or 9 but my server people are sluggish with upgrades.

Thanks
Was This Post Helpful? 0

#3 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: ColdFusion

Posted 08 April 2010 - 06:51 AM

Well, I don't know much about PHP but from what the mighty Google tells me, that function manually inserts line breaks in front of newline calls in a string.

CF has an entire array of string manipulation functions. One of them probably does what you want. I'd answer your question more definitively except the examples I saw on the web illustrating the PHP function example had "/n" in them. CF will take user input from a normal form text or textarea field and simply keep whatever it was that the user typed and faithfully stick that in the database. So, unless the user actually typed "/n" in their input, it wouldn't really come into play.

However, let's assume that a user did do that. One of the nice things about CF is the ease of making a user defined function. In this case, however, it wouldn't even need to be that difficult. You'd simply use a ReplaceNoCase() function like so:

<cfset variables.someString = "This string has one line.\nAnd now another line.">
<cfset variables.someStringFixed = ReplaceNoCase(variables.someString,"\n","<br />","ALL">


You can make that into a callable UDF if you find you're doing the same function over and over again and want to be consistent across your codebase...or you can just use ReplaceNoCase() wherever you need it.

CF has all kinds of prebuilt string functions which you can peruse here and the CFLib site is a nice repository of UDFs that other devs have built and shared. The string manipulation UDFs on CFLib are found here.

Good luck!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1