|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
How to prevent cfhtmlhead content from being inserted into cfmail
Hi, all...Rick Faircloth 05/22/12 02:27 P > Is there any way to prevent the JS being output using cfsavecontent and aRaymond Camden 05/22/12 03:09 P I figured it would be something straight-forward like that. :o)Rick Faircloth 05/22/12 04:15 P Ray, can you (or any of your other guys) give me an exampleRick Faircloth 05/22/12 07:14 P > Ray, can you (or any of your other guys) give me an exampleRaymond Camden 05/22/12 10:26 P Well, apparently, I can conditionally comment out any of theRick Faircloth 05/22/12 11:51 P > Well, apparently, I can conditionally comment out any of theRaymond Camden 05/23/12 07:25 A The JS and CF affected by the commenting is in the onRequestStartRick Faircloth 05/23/12 07:46 A You are confusing requests here.Raymond Camden 05/23/12 07:52 A > If the file, employment-application.cfm, includes a <script> tag thatRick Faircloth 05/23/12 08:56 A > Perhaps I should tryRick Faircloth 05/23/12 09:09 A Woot. Glad you got it.Raymond Camden 05/23/12 11:10 A Rick that might be a good case to think about the application, and oneAndrew Scott 05/22/12 04:20 P I need variables like these (these are just part of the variables)Rick Faircloth 05/22/12 06:29 P It would be much better to use an include for your HTML <head> (in yourMatt Quackenbush 05/22/12 06:38 P > Just output #application.whatever# in the js.Rick Faircloth 05/22/12 06:43 P If you used a front controller, you'd only have to type it once (perMatt Quackenbush 05/22/12 06:55 P One problem I can see with this approach is created because of the way IRick Faircloth 05/22/12 06:53 P There are lots of ways to create a title variable. It really depends uponMatt Quackenbush 05/22/12 06:56 P If every page has a different title, then there has to be a title variableRick Faircloth 05/22/12 07:18 P Hi, all... I've got a cfhtmlhead tag set up in my application CFC that defines some JS variables for CF use and vice-versa. They're inserted into the head of every page. I noticed, when running an sequence involving an HTML form - jQuery ajax call - CFC method - and JSON data return, that the JS variables are being inserted into the JSON return data from the ajax call. This is throwing off my "success" processing after the call. Is there any way to prevent the JS being output using cfsavecontent and a variable in the CFC from ending up in the JSON data return? The CFMAIL is processed fine and the mail goes out, but the extra data beyond "success" in the JSON is preventing and further JS statement from processing...basically, the "Processing..." message isn't being hidden and the "Thank You" message isn't being shown after the form is processed and the mail is sent. I didn't want to get into all the code up front in case there's a simple way to handle this. Thanks for any feedback! If you need to see some code, let me know! Rick > Is there any way to prevent the JS being output using cfsavecontent and a > variable > in the CFC from ending up in the JSON data return? Sure. In your onRequestStart, simply check the requested file. If it ends in .cfc, stop doing that. -- =========================================================================== Raymond Camden, Adobe Developer Evangelist Email : raymondcamden@gmail.com Blog : www.raymondcamden.com Twitter: cfjedimaster I figured it would be something straight-forward like that. :o) Thanks, Ray! Rick cfmail... > > Is there any way to prevent the JS being output using cfsavecontent and a > variable > in the CFC from ending up in the JSON data return? Sure. In your onRequestStart, simply check the requested file. If it ends in .cfc, stop doing that. -- =========================================================================== Raymond Camden, Adobe Developer Evangelist Email : raymondcamden@gmail.com Blog : www.raymondcamden.com Twitter: cfjedimaster Ray, can you (or any of your other guys) give me an example of how to code to "check the requested file" ??? And I'm not sure what file I'm actually checking for. You mentioned checking to see if the requested file is a .cfc, but my code for this problem flows from a .cfm to a .js, then to a .cfc, back to a .js and them back to the original .cfm. Is there some way just to check and see if the original .cfm is named "employment-application.cfm" and then, if so, use a condition cfif to stop the cfhtmlhead from being used in the onRequestStart in the application.cfc? (I'm beginning to appreciate the extra work of cfincluding my variables per page, just to avoid this kind of issue when using AJAX!) I don't understand why the variable set in onRequestStart, "js_variables" gets included in the JSON response, anyway. cfmail... > > Is there any way to prevent the JS being output using cfsavecontent and a > variable > in the CFC from ending up in the JSON data return? Sure. In your onRequestStart, simply check the requested file. If it ends in .cfc, stop doing that. -- =========================================================================== Raymond Camden, Adobe Developer Evangelist Email : raymondcamden@gmail.com Blog : www.raymondcamden.com Twitter: cfjedimaster > Ray, can you (or any of your other guys) give me an example > of how to code to "check the requested file" ??? onRequestStart is passed one attribute, the name of the file being requested. You can use list functions on it if you want - <cffunction name="onRequestStart"> <cfargument name="thepage"> <cfset var extension = listLast(thepage, ".")> <!--- logic here to do stuff if .cfc --> > I don't understand why the variable set in onRequestStart, "js_variables" > gets included in the JSON response, anyway. Because onRequestStart means just that - run it every time you request a CFC or CFM. Well, apparently, I can conditionally comment out any of the CF based on the requesting file. However, the JS isn't affected by the conditional comments and still shows up in the JSON, causing the JS to stop processing. Once I remove the JS, the processing occurs normally. Looks like I'm going to have to rewrite a lot of pages and use cfinclude the js_variables where needed. Bummer... PS - I appreciate the tip on "thepage" variable passed onRequestStart. I didn't find that in the docs, specifically, nor in other Google searches. Rick cfmail... > > Ray, can you (or any of your other guys) give me an example > of how to code to "check the requested file" ??? onRequestStart is passed one attribute, the name of the file being requested. You can use list functions on it if you want - <cffunction name="onRequestStart"> <cfargument name="thepage"> <cfset var extension = listLast(thepage, ".")> <!--- logic here to do stuff if .cfc --> > I don't understand why the variable set in onRequestStart, "js_variables" > gets included in the JSON response, anyway. Because onRequestStart means just that - run it every time you request a CFC or CFM. > Well, apparently, I can conditionally comment out any of the > CF based on the requesting file. However, the JS isn't affected > by the conditional comments and still shows up in the JSON, causing > the JS to stop processing. Once I remove the JS, the processing > occurs normally. Is your JS in a CFM file? If so, it doesn't matter. CF doesn't care if you output HTML, JS, or Klingon. If it is a CFM or a CFC _file_, then onRequestStart will fire. > PS - I appreciate the tip on "thepage" variable passed onRequestStart. > I didn't find that in the docs, specifically, nor in other Google searches. It is there - in the CFML Reference, chapter 8 (well, for CF10) is: Application CFC Reference The JS and CF affected by the commenting is in the onRequestStart function in the application.cfc: <cfsavecontent variable = "jsVariables"> <!--- [ js version of cf variables ] ---> <cfset js_sitename = application.sitename /> <cfset js_website = application.website /> <cfset js_site_manager_dsn = application.site_manager_dsn /> <cfset js_client_dsn = application.client_dsn /> <cfoutput> <script type="text/javascript"> var js_sitename = '#js_sitename#'; var js_website = '#js_website#'; var js_site_manager_dsn = '#js_site_manager_dsn#'; var js_client_dsn = '#js_client_dsn#'; </script> </cfoutput> </cfsavecontent> <cfhtmlhead text = "#jsVariables#" /> If I use: <cfif listLast(arguments.thepage, '/') is not "employment-application.cfm"> </cfif> around the code above, it prevents the insertion of code into the head of employment-application.cfm, but the lines between and including, "<script type="text/javascript">...</script>" still get inserted into the JSON produced by an AJAX call from employment-application.cfm. cfmail... > Well, apparently, I can conditionally comment out any of the > CF based on the requesting file. However, the JS isn't affected > by the conditional comments and still shows up in the JSON, causing > the JS to stop processing. Once I remove the JS, the processing > occurs normally. Is your JS in a CFM file? If so, it doesn't matter. CF doesn't care if you output HTML, JS, or Klingon. If it is a CFM or a CFC _file_, then onRequestStart will fire. > PS - I appreciate the tip on "thepage" variable passed onRequestStart. > I didn't find that in the docs, specifically, nor in other Google searches. It is there - in the CFML Reference, chapter 8 (well, for CF10) is: Application CFC Reference You are confusing requests here. If the file, employment-application.cfm, includes a <script> tag that points to a CFM, that's a _second_ request, not the same as the first one. If it requests something like javascript.cfm, then your onRequestStart needs to recognize that too. ----- Excess quoted text cut - see Original Post for more ----- > If the file, employment-application.cfm, includes a <script> tag that points to a CFM... It doesn't. Here are the files involved: 1) employment-application.cfm 2) application.cfc 2) employment-application-form-processing.js 3) employment-application.cfc employment-application.cfm has the above js file included via a script link. The js file has an AJAX call to a method in employment-application.cfc for processing the form contained in the .cfm above. employment-application.cfc, as well as processing the form, also sends a couple of cfmail messages, if processing is successful. After successful processing of the form and sending of the cfmail messages in the cfc method, JSON is sent back to the AJAX call in the js file, which then, as the final step, should change the "processing" message the user sees on the form to a "success" message. But because the JSON includes more than just the message "FORMSTATUS:SUCCESS" in its content, which is the js script from the onRequestStart method in the application.cfc, the js won't complete the last step. I'm just trying to find a way to prevent the js script that gets inserted into the head of each page from being included in the JSON data returned. I don't need the js variables that are included via the onRequestStart for the employment-application.cfm page, so I was trying to find a way to prevent application.cfc from processing the js variables if the requesting page is employment-application.cfm. Your suggestion to use <cfif listLast(thepage, '/') is not "employment-application.cfm"> </cfif> worked fine, to bypass the CF code processing the application.cfc, but the js script contained inside the conditional statement still shows up in the JSON. Either the conditional statement above won't afffect the inclusion <script></script> tag contained in the onRequestStart method or the AJAX call from the js file to the employment-application.cfc method also triggers the onRequestStart method and that causes the JSON to include the js script code. Perhaps I should try <cfif listLast(thepage, '/') is not "employment-application.cfc"> </cfif> and see if that works. I'll give that a try. Does any of this make sense? Rick cfmail... You are confusing requests here. If the file, employment-application.cfm, includes a <script> tag that points to a CFM, that's a _second_ request, not the same as the first one. If it requests something like javascript.cfm, then your onRequestStart needs to recognize that too. ----- Excess quoted text cut - see Original Post for more ----- > Perhaps I should try > <cfif listLast(thepage, '/') is not "employment-application.cfc"> > </cfif> > and see if that works. That seems to have worked, on the initial test. The JSON response doesn't include the js script tags and content as it did when I used "employment-application.cfm", instead of the .cfc above. I hadn't thought that the "employment-application.cfc" file would be considered the requesting file by the onRequestMethod when the method in employment-application.cfc involved ran. That being the case, I can understand how the js script gets included in the JSON, because the onRequestStart "cfoutput's" the js script in order to assign value to the CF variables using ##'s inside the js script. i.e. <cfoutput> <script type="text/javascript"> var js_client_dsn = '#client_dsn#'; </script> </cfoutput> I don't *think* that I can assign the value to the var without using cfoutput and the ##'s around the CF variables. The only thing I know at this point for sure is that I have a working solution to the form processing for an impatient client. So, this hack will have to stand for now. Now to see if this works on the production site. :o) Rick cfmail... > If the file, employment-application.cfm, includes a <script> tag that points to a CFM... It doesn't. Here are the files involved: 1) employment-application.cfm 2) application.cfc 2) employment-application-form-processing.js 3) employment-application.cfc employment-application.cfm has the above js file included via a script link. The js file has an AJAX call to a method in employment-application.cfc for processing the form contained in the .cfm above. employment-application.cfc, as well as processing the form, also sends a couple of cfmail messages, if processing is successful. After successful processing of the form and sending of the cfmail messages in the cfc method, JSON is sent back to the AJAX call in the js file, which then, as the final step, should change the "processing" message the user sees on the form to a "success" message. But because the JSON includes more than just the message "FORMSTATUS:SUCCESS" in its content, which is the js script from the onRequestStart method in the application.cfc, the js won't complete the last step. I'm just trying to find a way to prevent the js script that gets inserted into the head of each page from being included in the JSON data returned. I don't need the js variables that are included via the onRequestStart for the employment-application.cfm page, so I was trying to find a way to prevent application.cfc from processing the js variables if the requesting page is employment-application.cfm. Your suggestion to use <cfif listLast(thepage, '/') is not "employment-application.cfm"> </cfif> worked fine, to bypass the CF code processing the application.cfc, but the js script contained inside the conditional statement still shows up in the JSON. Either the conditional statement above won't afffect the inclusion <script></script> tag contained in the onRequestStart method or the AJAX call from the js file to the employment-application.cfc method also triggers the onRequestStart method and that causes the JSON to include the js script code. Perhaps I should try <cfif listLast(thepage, '/') is not "employment-application.cfc"> </cfif> and see if that works. I'll give that a try. Does any of this make sense? Rick cfmail... You are confusing requests here. If the file, employment-application.cfm, includes a <script> tag that points to a CFM, that's a _second_ request, not the same as the first one. If it requests something like javascript.cfm, then your onRequestStart needs to recognize that too. ----- Excess quoted text cut - see Original Post for more ----- Woot. Glad you got it. ----- Excess quoted text cut - see Original Post for more ----- Rick that might be a good case to think about the application, and one reason why you need to keep things out of the Application.cfc that really don't need to be there. If you must continue with it, then you might need to look for a conditional statement to not include the JS etc for the CFHTMLHEAD, but on the other side of your question you can use cfsavecontent to create a variable and use that with CFHTMLHEAD. -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 On Wed, May 23, 2012 at 4:26 AM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- I need variables like these (these are just part of the variables) on every page of the site, useable as CF and JS variables: <cfsavecontent variable = "jsVariables"> <!--- [ js version of cf variables ] ---> <cfset js_sitename = application.sitename /> <cfset js_website = application.website /> <cfset js_site_manager_dsn = application.site_manager_dsn /> <cfset js_client_dsn = application.client_dsn /> <cfoutput> <script type="text/javascript"> var js_sitename = '#js_sitename#'; var js_website = '#js_website#'; var js_site_manager_dsn = '#js_site_manager_dsn#'; var js_client_dsn = '#js_client_dsn#'; </script> </cfoutput> </cfsavecontent> <cfhtmlhead text = "#jsVariables#" /> Why would putting this code directly in the head of each page be better than using cfhtmlhead? cfmail... Rick that might be a good case to think about the application, and one reason why you need to keep things out of the Application.cfc that really don't need to be there. If you must continue with it, then you might need to look for a conditional statement to not include the JS etc for the CFHTMLHEAD, but on the other side of your question you can use cfsavecontent to create a variable and use that with CFHTMLHEAD. -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 On Wed, May 23, 2012 at 4:26 AM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- inserted ----- Excess quoted text cut - see Original Post for more ----- It would be much better to use an include for your HTML <head> (in your layout template) than to use cfhtmlhead in the app CFC. Also, there is no reason to set all of those 'js_whatever' variables. Just output #application.whatever# in the js. Your include file might look something like so: <head> <!-- all of your standard css/js links, scripts, etc., including the js you've just shown --> <title>bla bla</title> </head> So each page (or layout) simply does a <cfinclude tempate="/includes/html_head.cfm" />. HTH On Tue, May 22, 2012 at 5:28 PM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- > Just output #application.whatever# in the js. Seems like when I first started trying to use CF variables in JS, I couldn't. I'll have to revisit this approach. > So each page (or layout) simply does a <cfinclude tempate="/includes/html_head.cfm" />. But with this approach, I still have to type that line on every page in the app. With onRequestStart, I only have to type it once. Is the reason *not* to set the variables in onRequestStart so that they won't interfere with just such situations as mine? Or are there other reasons where it causes problems? cfmail... It would be much better to use an include for your HTML <head> (in your layout template) than to use cfhtmlhead in the app CFC. Also, there is no reason to set all of those 'js_whatever' variables. Just output #application.whatever# in the js. Your include file might look something like so: <head> <!-- all of your standard css/js links, scripts, etc., including the js you've just shown --> <title>bla bla</title> </head> So each page (or layout) simply does a <cfinclude tempate="/includes/html_head.cfm" />. HTH On Tue, May 22, 2012 at 5:28 PM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- conditional ----- Excess quoted text cut - see Original Post for more ----- a ----- Excess quoted text cut - see Original Post for more ----- is > > preventing > > and further JS statement from processing...basically, the "Processing..." ----- Excess quoted text cut - see Original Post for more ----- If you used a front controller, you'd only have to type it once (per layout/theme). :-) Setting variables in onRequestStart() is perfectly fine and dandy. It's often a problem when you use onRequestStart() to *render output*, though. (Yes, technically speaking, cfhttphead doesn't render output directly, but for all intents and purposes, it does.) On Tue, May 22, 2012 at 5:42 PM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- One problem I can see with this approach is created because of the way I set up my files. A page and its accompanying individual js and css files (no, I don't create a single monster js or css file, but rather many smaller ones inside "module" folders that contain the .cfm, .cfc, .css, and .js specific to a particular module. There are *many* more files that way, but I don't find the increased number of http requests to be a problem. I do it this way to help me keep my sanity when trying to manage so much code. And for a more "down-to-earth" question... what if the <title> of a page was different for every page? Even if everything else was the same for each page (all links, etc.), how would you use a variable to create different titles for all the pages? Maybe I'm just having a brain cramp and can't see the forest for the trees... cfmail... It would be much better to use an include for your HTML <head> (in your layout template) than to use cfhtmlhead in the app CFC. Also, there is no reason to set all of those 'js_whatever' variables. Just output #application.whatever# in the js. Your include file might look something like so: <head> <!-- all of your standard css/js links, scripts, etc., including the js you've just shown --> <title>bla bla</title> </head> So each page (or layout) simply does a <cfinclude tempate="/includes/html_head.cfm" />. HTH On Tue, May 22, 2012 at 5:28 PM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- conditional ----- Excess quoted text cut - see Original Post for more ----- a ----- Excess quoted text cut - see Original Post for more ----- is > > preventing > > and further JS statement from processing...basically, the "Processing..." ----- Excess quoted text cut - see Original Post for more ----- There are lots of ways to create a title variable. It really depends upon how you have your application architecture setup. :-) <title>#myBadAssPageTitle#</title> On Tue, May 22, 2012 at 5:52 PM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- If every page has a different title, then there has to be a title variable set for each page *somewhere*... I've never used an include for the entire head portion of a page, so, "it really depends upon how have your application architecture setup" is lost on me, since I'm not familiar with the options you're referring to. cfmail... There are lots of ways to create a title variable. It really depends upon how you have your application architecture setup. :-) <title>#myBadAssPageTitle#</title> On Tue, May 22, 2012 at 5:52 PM, Rick Faircloth <Rick@whitestonemedia.com>wrote: ----- Excess quoted text cut - see Original Post for more ----- really ----- Excess quoted text cut - see Original Post for more ----- and ----- Excess quoted text cut - see Original Post for more -----
|
May 24, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||