?
Solved

How to escape quotes?

Posted on 2003-10-27
11
Medium Priority
?
3,287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 800 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 400 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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…
What You Need to Know when Searching for a Webhost Provider
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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