Solved

How to escape quotes?

Posted on 2003-10-27
11
3,283 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

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…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

689 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