Solved

How to escape quotes?

Posted on 2003-10-27
11
3,265 Views
Last Modified: 2013-12-24
A simple question that's holding me up, so I gave it 250! I'm using CDO to send an e-mail where the message body is built based on form responses... problem is inside the declaration of the message body, I need to write extensive CF logic to build the message body. This code contains quotes, so it is bombing. A short example...

<cfset objNewMail.Body = "Date of registration: #dateformat(now(),"mm/dd/yy")# #CHR(13)#
<cfif #lcase(FORM.CDIpreconf)# is "yes">
Career Development Institute #CHR(13)#</cfif>
">

While this example is very short, the real deal is about 50 lines of this. Is there a way to tell ColdFusion to parse through a block of code, put the result out to a variable, and then I could just use the variable? I'm putting pretty much the same information to the page for the user to view as a confirmation and that of course works without issue.
0
Comment
Question by:alyoung
11 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 200 total points
ID: 9627500
You can do a couple things; if you want to use double quotes inside double quotes do this:
<cfset objNewMail.Body = "Date of registration: #dateformat(now(),"mm/dd/yy")# #CHR(13)#
<cfif #lcase(FORM.CDIpreconf)# is ""yes"">
Career Development Institute #CHR(13)#</cfif>
">
Or you can single quotes inside double quotes like this:

<cfset objNewMail.Body = "Date of registration: #dateformat(now(),'mm/dd/yy')# #CHR(13)#
<cfif #lcase(FORM.CDIpreconf)# is 'yes'>
Career Development Institute #CHR(13)#</cfif>
">

Or you can use double quotes inside single quotes like this:

<cfset objNewMail.Body ='Date of registration: #dateformat(now(),"mm/dd/yy")# #CHR(13)#
<cfif #lcase(FORM.CDIpreconf)# is "yes">
Career Development Institute #CHR(13)#</cfif>
'>

To escape single or double quotes simply do this “Jeff said “”Go away”” ” or ‘Jeff said ‘’Go away’’ ‘
0
 
LVL 6

Assisted Solution

by:PE_CF_DEV
PE_CF_DEV earned 100 total points
ID: 9627626
The code example you gave us will not work no matter how you escape the quotes you can not, as far as I know, embed <cfif> inside the cfset tag. you will need to use iif() instead.

Check out this link for a good explanationon iif:

http://www.fusionauthority.com/iif.cfm

or do something like:

<cfset objNewMail.Body = "Date of registration: #dateformat(now(),"mm/dd/yy")# #CHR(13)#">
<cfif #lcase(FORM.CDIpreconf)# is "yes">
      <cfset objNewMail.Body="#objNewMail.Body# Career Development Institute #CHR(13)#">
</cfif>
0
 

Author Comment

by:alyoung
ID: 9627627
Hmmm. Must be something specific to this situation. For I'd tried using single quotes within, but it still didn't work. Tried doubling double quotes within double quotes--didn't work.

I thought perhaps it was because it was breaking over one line so I condensed it all down to one line. That didn't work either.

Is there a way to just build this body and throw it into a variable and then just use that in the object setup?

0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9627718
if you go to this url http://sylvansupply.com/test.cfm? you can see a working an eample.
0
 

Author Comment

by:alyoung
ID: 9627809
Ew, I was afraid of this... I'm going to have to build the message body in pieces first, throwing it into a variable. Then just use the variable in the CFSET for the message body.

Ugh.  =-)  
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 9

Expert Comment

by:CFDevHead
ID: 9627819
post all of the code an maybe we can help.
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9628108
alyoung,
Are you going to post your code?
0
 
LVL 4

Assisted Solution

by:procept
procept earned 200 total points
ID: 9628741
Hi,

<cfsavecontent> will save everything between start and end tag in a variable:

<cfsavecontent variable="myVar">
< --- output anything here --->
</cfsavecontent>

That tag is new in CF MX; for earlier versions you need a custom tag; there should be some in the tag gallery, if you can't find one, let me know, I'll send you something that works...

HTH,

Chris
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9628925
any luck?
0
 
LVL 11

Expert Comment

by:hart
ID: 9631583
bingo procept

use
<cfsavecontent variable="myVar">
   <cfif>...</cfif>
   <cfloop> anything...
</cfsavecontent>

and then in ur mail just use the myVar

<cfmail from="some address" to="address" subject="Your SUbject" type="HTML">
#myVar#
</cfmail>

Thats it

or if u r not using latest version of cf then

<cfset somevar = 'your data'>
just replace the what ever single quotes are there in the data with double quotes or u can do the same thing vice versa

Regards
Hart
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9650513
any luck
0

Featured Post

New! My Passport Wireless Pro Wi-Fi Mobile Storage

Portable wireless storage to offload, edit, and stream anywhere.

High-capacity, wireless mobile storage designed to accompany professional photographers and videographers in the field to easily offload, edit and stream captured photos and high-definition videos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Transferring website to another host 7 57
How to switch email hosts (part 2) 11 65
IPA - can it be run on a web server? 3 143
IIS Site Configuration Copy 2 70
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now