Solved

How to escape quotes?

Posted on 2003-10-27
11
3,264 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

19 Experts available now in Live!

Get 1:1 Help Now