[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3297
  • Last Modified:

How to escape quotes?

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
alyoung
Asked:
alyoung
3 Solutions
 
CFDevHeadCommented:
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
 
PE_CF_DEVCommented:
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
 
alyoungAuthor Commented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
CFDevHeadCommented:
if you go to this url http://sylvansupply.com/test.cfm? you can see a working an eample.
0
 
alyoungAuthor Commented:
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
 
CFDevHeadCommented:
post all of the code an maybe we can help.
0
 
CFDevHeadCommented:
alyoung,
Are you going to post your code?
0
 
proceptCommented:
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
 
CFDevHeadCommented:
any luck?
0
 
hartCommented:
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
 
CFDevHeadCommented:
any luck
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now