Link to home
Start Free TrialLog in
Avatar of larksys
larksys

asked on

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

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

Avatar of Plucka
Plucka
Flag of Australia image

Inserting a #chr(10)##chr(13)# should work
Avatar of SidFishes
maybe i'm not understanding but why not




Avatar of larksys
larksys

ASKER

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.
Avatar of larksys

ASKER

and....... inserting #chr(10)##chr(13)# didn't work either.
Avatar of larksys

ASKER

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?

<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>


ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
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
Avatar of larksys

ASKER

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.
Avatar of larksys

ASKER

I missed the last post.  That solved the margin problem. Many thanks.