?
Solved

CFML - need some trick code - adding line feed to text in cfdocument

Posted on 2009-04-29
9
Medium Priority
?
575 Views
Last Modified: 2012-08-13
I am printing envelopes from sql database table.  The problem is some addresses have a second line and some do not. I don't want to print an address with a blank line in it. This is a quasi mail-merge function where the document is merged with the data.  I've included the code that generates the data and the code that processes that data.  I tried modifying the rereplace code to add a line feed. That didn't work. So, I tried adding a line feed to the actual data for address line 1. This isn't working either.
Prior to cfdocument;
 
<cfif QMailers.address2 gt "">
   <cfset QMailers.address1 = "#QMailers.address1#" & chr(10) />
</cfif>
<cfquery name="QWriteMailersEnvelope" datasource="#request.dsn#">
   Insert Into Mailers_Envelopes
(envelope_mailer_id,envelope_document_id,envelope_date,envelope_firstname,envelope_lastname,envelope_address_1,envelope_address_2,envelope_city,envelope_state,envelope_zip,envelope_country,envelope_user_id,envelope_consultant_id,envelope_company)
 Values(<cfqueryparam value="#QMailers.id#" cfsqltype="cf_sql_integer">,
<cfqueryparam value="0" cfsqltype="cf_sql_integer">,
<cfqueryparam value="#dateformat(now(),"yyyy/mm/dd")#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#QMailers.firstname#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#QMailers.lastname#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#QMailers.address1#" cfsqltype="cf_sql_varchar"> ,
<cfqueryparam value="#QMailers.address2#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#QMailers.city#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#QMailers.state#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#QMailers.zipcode#"cfsqltype="cf_sql_varchar">,					        <cfqueryparam value="#QMailers.country#" cfsqltype="cf_sql_varchar">,  
<cfqueryparam value="#QMailers.usersid#" cfsqltype="cf_sql_integer">,
<cfqueryparam value="#QMailers.default_sender#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#QMailers.company_name#" cfsqltype="cf_sql_varchar">)  
</cfquery>
 
create the document;
<cfdocumentsection>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_Text#,"!Firstname!","#QEnvelopes.envelope_firstname#","all")>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_Text#,"!Lastname!","#QEnvelopes.envelope_lastname#","all")>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!Address Line 1!","#QEnvelopes.envelope_address_1#","all")>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!Address Line 2!","#QEnvelopes.envelope_address_2#","all")>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!City!","#QEnvelopes.envelope_City#","all")>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!State!","#QEnvelopes.envelope_State#","all")>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!Zip!","#QEnvelopes.envelope_Zip#","all")>
<cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!Country!","#QEnvelopes.envelope_country#","all")>        
#QEnvelopes.Document_text#
</cfdocumentsection>

Open in new window

0
Comment
Question by:larksys
9 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 24266675
Inserting a #chr(10)##chr(13)# should work
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 24266689
maybe i'm not understanding but why not




0
 
LVL 1

Author Comment

by:larksys
ID: 24266713
I guess I should show the original document;
                                                                                            !Firstname! !Lastname!
                                                                                            !Address Line 1!!Address Line 2!
                                                                                            !City!, !State! !Zip!
                                                                                            !Country!

This is an envelope format and the document is maintained by FCKeditor.  I'm going to have a small problem lining up the 2nd address line even if I do get it to move to the next line.  Address Line 2 is at the end of Address Line 1 so I don't have to worry about it if it's blank.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 1

Author Comment

by:larksys
ID: 24266764
and....... inserting #chr(10)##chr(13)# didn't work either.
0
 
LVL 1

Author Comment

by:larksys
ID: 24266845
I'm a little foggy about this next question, but couldn't I solve the problem by modifying the document in FCKeditor with some HTML or CFML?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 24269818

<cfdocument> understands HTML, I would think added a <BR> would do it.

But to avoid having the <BR> appear when there is no value, you can add a CFIF statement to check to see if the address2 has a value, if not, then just clear the ! variable...

<cfif len(QEnvelopes.envelope_address_2)>
    <cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!Address Line 2!","<BR>#QEnvelopes.envelope_address_2#","all")>
<cfelse>
    <cfset QEnvelopes.Document_Text = ReReplace(#QEnvelopes.Document_text#,"!Address Line 2!","","all")>
</cfif>


0
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 total points
ID: 24269925
I'm thinking you are defeating the purpose of allowing the user to setup their own design by adding your own logic into the mix.  Forcing a line break before the address2 field would be unexpected by the user.  If I were the user I would setup the address2 on a separate line.. then you would have two line breaks?

Perhaps you should work from this as a starting point..

           !Firstname! !Lastname!
           !Address Line 1!
           !Address Line 2!
           !City!, !State! !Zip!
           !Country!

Save this into a variable

<cfcontentvariable variable="theAddres">
           !Firstname! !Lastname!
           !Address Line 1!
           !Address Line 2!
           !City!, !State! !Zip!
           !Country!
</cfcontentvariable>

Then use a regular expression to string out any extra lines

Then you can take the variable and put into into a DIV to position it to the far right of the envenlope and ensure that the left sides are all aligning...

<cfdocument...>
  <div style="margin-left:400px;">
    #theAddress
   </div>
</cfdocument>


Something like that...
?
0
 
LVL 1

Author Comment

by:larksys
ID: 24270969
That worked just fine.  Many thanks.  I have to adjust for the spacing to line up address line 2 with the rest of the address block, but that should be easy.
0
 
LVL 1

Author Closing Comment

by:larksys
ID: 31576269
I missed the last post.  That solved the margin problem. Many thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question