ColdFusion Language

10K

Solutions

3K

Contributors

ColdFusion is a server-side rapid application development platform originally created by Allaire and now sold by Adobe, implementing the dynamic general purpose CFML programming language. The term ColdFusion is sometimes colloquially used to refer to the CFML language (Cold Fusion Markup Language), but can also include discussions of the server software implementation. ColdFusion runs using a customised version of Apache Tomcat. Earlier versions are bundled with JRun.

Share tech news, updates, or what's on your mind.

Sign up to Post

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code.

The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a couple of header and footer sections. Also it was using a database query to loop over the records and display inside the cfdocument code to create a PDF file on the fly and display it in the browser.

This code shows what it was doing, I searched for this Issue but could not a find a answer so i tried different ways to tackle and found one very good solution.
 

<cfdocument format="PDF" localURL="yes">
	<cfoutput query="myquery">
		<!--- Section 1 --->
		<cfdocumentsection name="Section1-#myquery.id#">
		    <cfdocumentitem type="header">
		    <h1>This is a Header</h1>
		    </cfdocumentitem>
                    <table align="center"><tr><td>counter my query</td></tr></table>    
		    <cfdocumentitem type="footer">
		    <h1>Page #cfdocument.currentPageNumber# of #cfdocument.totalPageCount#</h1>
		    </cfdocumentitem>
		</cfdocumentsection>
		<cfdocumentsection name="Section2-#myquery.id#">
		    <cfdocumentitem type="header">
		    <h1>2nd header</h1>
		    </cfdocumentitem>
		    <table align="center"><tr><td>counter my query 2</td></tr></table>   
		    <cfdocumentitem type="footer">
		    <h1>Page #cfdocument.currentPageNumber# of #cfdocument.totalPageCount#</h1>
		    </cfdocumentitem>
		

Open in new window

0
On Demand Webinar - Networking for the Cloud Era
LVL 9
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented.

Please note, this article was intended for those that have some idea of what Coldfusion and SOLR are, but lack the experience on how to use them together.

I will be writing a guide soon on how to install SOLR 4.3 with Coldfusion. While Coldfusion comes with SOLR 1.5 built in, 4.3 has much better capabilities.

First, we need to declare our server host, port, and version.

<cfset SOLR_SERVER_HOST = 'localhost'>
<cfset SOLR_SERVER_PORT = '8983'>
<cfset SOLR_SERVER_VERSION = '4.3'>

Open in new window


I also like to declare a global variable for each collection name.

<cfset endUserCollection = "end_user">

Open in new window


I created the function below called SOLR_SEARCH.

<cffunction name="SOLR_SEARCH" returnType="struct" output="yes">

  <cfargument name="collection" type="string" required="true" default="">
  <cfargument name="criteria" type="string" required="false" default="*:*">
  <cfargument name="startrow" type="string" required="false" default="0">
  <cfargument name="maxrows" type="string" required="false" default="10">
  <cfargument name="sort" type="string" required="false" default="">
  <cfargument name="columns" type="string" required="false" 

Open in new window

0
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authorize a script to access Eventful to download their events.

What is OAuth?

According to Wikipedia, OAuth (Open Authorization) is an open standard that allows users to share their private resources (e.g. photos, videos, contact lists) stored on one site with another site without having to hand out their credentials, typically username and password.

Let's talk about the code below:

The following code generates the HMAC-SHA1 authentication code required by OAuth. Contrary to ColdFusion's documentation, HMAC-SHA1 is not supported by the Encrypt (or Hash) functions.  The workaround is a simple HMAC-SHA1 CFFunction

HMAC Function
The next bit of code generates the OAuth "base string" from the parameters of your OAuth request.

OAuth BaseString Function
Next, we enhance ColdFusion's URLEncoded() function to produce strings compliant with RFC 3986. ColdFusion's URLEncodedFormat function is not 100% compliant with RFC 3986 and will trip up OAuth's sensitive string calculations.

Enhanced URLEncode Function
This is the engine of the OAuth car. Generates the OAuth request header and signature, submits to the provider (e.g., Twitter) and returns the response in a string. In accordance with the OAuth specification, the callback URL is twice URL encoded.

OAuth Authorization Function
0
 
LVL 2

Author Comment

by:ColdfusionAdmins
Comment Utility
Thanks for giving me the chance to respond.

Please see the comment in the article that states, "In addition, special thanks to David Reiter from eventful.com for helping solve the OAuth authorization."

I am the author of the code. Please email dreiter@eventful-inc.com and he can confirm this.

I could also forward an email reference from him that he was going to include my code in his documentation for other coldfusion developers.

In fact, I have attached our entire email conversation.

Sincerely,
Travis Walters
proof.txt
0
Hi.
There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them .
I did keep the main js functions but made several changes.
To understand the code you must be familiar with little of jquery and html/cfml file uploading. I'm using html 4 , jquery ajaxForm and CF 8 + for uploading , editing  and showing the images to the user without page refresh.

Changes to the main code from www.randhawaworld.com:
1. Add - delete "n" file inputs
2. Js filesize validation (not for IE < 10)
3. js extension validation
4. Using a cfc instead of cfm and use the advantage to return an array with "n" data
5. server side size and file validation using IsImageFile tag instead of using the accept attribute in the cffile action="upload" tag
6. renaming
7. resizing using the very interesting and useful ImageScaleToFitb tag.
8. returning an array with all needed values like totalerros,errormessages,uploaded totalsize, uploaded images a.s.o
9. Finally use these array to show messages and images using jquery.

In most browsers it is working fine except........Internet Explorer

There are some issues using this with IE. The progress bar is showing only 0% onuploading. IE 10 is showing 1%. Well i hope somebody could fix this.


I will be very happy you like.
I also would like to thank myselfrandhawa for his help.

Time to go to the …
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
Comment Utility
Great work @panosms, CF Community will be all thankful for this wonderful tutorial

Keep up the Good work
0
CFGRID Custom Functionality Series -  Part 1


Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achieved what I needed. Here I will demonstrate how this thing can be done in ColdFusion CFGRID and in easy Way. Nothing extra ordinary is required, Just a Basic Knowledge of How JavaScript works is Enough.

Let Me start with the Tutorial now.  I will split this tutorial in the following way.

1. Populate a CFGRID with CFC Binding and Show the DATA in the CFGRID
2. WE will create Custom Toolbar at Bottom for Showing the records
3. We will create the Hyperlink to the Column we need.
4. We will modify the Column to look a bit seperate so it can be noticed that this is a hyperlink
5. We will now open the cfwindow or the Normal window on the click of this link and see how it goes.

So we will start with the Code. I will show how we can populate the grid. The Following method is use to Populate Grid with my Bind Value

<cfoutput>
        <cfscript>
  args = {};
  args.bind = "cfc:CFC.myCFC.getDataForGrid({cfgridpage},{cfgridpagesize},
  {cfgridsortcolumn},{cfgridsortdirection})";
  args.delete = TRUE;
  args.format = "html";
  args.insert = false;
  args.name = "SchedulesGrid";
  args.pagesize = "5";
  args.selectmode = "browse";
  args.striperows = TRUE;
  args.autowidth = true;
  args.height = 

Open in new window

2
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
Comment Utility
Hi @bnwww- I will check with Coldfusion11 as it is been quite old article and will update accordingly, I cannot put the time frame here but will try to do as soon as possible

Cheers
0
 

Expert Comment

by:bnwww
Comment Utility
Thanks.  For those searching the best hint I found was a bug report on adobe's site https://bugbase.adobe.com/index.cfm?event=bug&id=3792163
0
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and brands.

This is not meant to be a tutorial on XSS & SQLi, merely some tips on how to prevent them when using ColdFusion. However, for the sake of clarity, I'll briefly outline what SQLi & XSS attacks look like.

An SQLi or SQL Injection attack is where a malicious user attempts to modify or obtain information from your database. This is accomplished by manipulating SQL statements that run your site.

A simple form post to search for an item on your hypothetical movie review site looks similar to this

<cfquery...>
	select * from tbl where name='#form.name#'
</cfquery>

Open in new window

Because the form input is unsanitized, it's a simple thing to pass the following
star wars'; DROP table MovieReviews --

Open in new window

which produces the following statement
      
select * from tbl where name='star wars'; DROP table MovieReviews --'

Open in new window

This retrieves the reviews for star wars and then DELETES your table. This works because many SQL servers allow chained statements. These are usually separated by a semi colon ;

The injected string fools the server into thinking that there are 2 separate statements by adding ; and manipulating the quotes.

Now you might say that an attacker won't know the name of your tables. There …
6
 
LVL 36

Author Comment

by:SidFishes
Comment Utility
Thanks for that update. We're still stuck at 8 but these new features sound great. Just proves my point "Coldfusion is one of, if not the easiest, web scripting language to code securely. Straight out of the box, it’s harder to run an SQLi attack against than most."

:)
0
 
LVL 3

Expert Comment

by:Eric Bourland
Comment Utility
Great article!

I have a couple of very small editorial notes which I hope are helpful:

The link to SQL Injection Blocker v.4 by Mary Jo Sminkey seems to be missing. I searched for it:

http://www.cfwebstore.com/index.cfm?fuseaction=blog.search

but did not find it. And it seems like Ms. Sminkey is no longer represented at CFWebStore? I could be wrong?

>>>Check that box and your done.

~you're

Thanks for this great article, Sid.

Eric
0
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again

Today, from the topic it is very clear that i will be showing you here the very basic usage of how we can upload the Image Uploading with jquery and preview and without any Page refresh.

The basic involves that you must be familiar with little bit of jquery and html/cfml file uploading. i am not going to use HTML 5 here, I will be working on HTML 4 and jquery to Upload the image and show the user without any Page refreshes.

There are many jquery Plugins or other Plugins which do the Uploading for you, But this is very Simple and you will love it, I bet

Now we had enough talk, let’s get down to the code now

So here is the code for the Basic page. This is quite simple as you will see that i have just added a simple upload button and we are doing the page processing, Now here is an update you can even add the javascript to this page to detect if user is uploading any other file rather than image file. you can add even more functions whatever you like like check javascript image size and others, That are all long things, you can do, so we start with Basic Info


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html" lang="en" />
<script 

Open in new window

1
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math. While this method is not one-hundred-percent foolproof, it gives a general idea of how we can slow down spammers a bit.

I have used many recaptcha codes like Lyla Captcha, Recaptcha, Coldfusion's own Captcha, and many others free and commercial captcha techniques. They all are not fully foolproof. Therefore, I find the Math method good as it does not involve image creation or something similar. Just create some simple math and you are done with it! If you want to play more with it, you can always do the following:

1. Follow Ben Nadel's post on Math De spamming Technique
2. Make the math Calculation more Complex
3. Add the reload functionality to this – e.g., build an Image of the calculation as new image and reload it again with a new image on same page.
 
A very tricky technique, though we will just be playing with the random numbers and sending the details the users to solve the math operation. While this technique uses only the multiplication, addition, and subtraction methods only, while more advanced techniques can be added like modulus, division, and other such operations.

But to keep it simple, I have included the following files I am using to make this work. I welcome all you suggestions and comments if you find any way to enhance the code!

Code Samples

1a. The first file, Application.cfm:

Open in new window

0
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and use them to help generate the Message!

So here below is the basic code of how to create a custom mail function, and what we can achieve in doing so!

While it is very basic code, up until now it has been working Ok! Functionality can be enhanced or extended just by adding few more features depending upon the Coldfusion version you are using!
 
Hope you find this article of interest and feel free to use the code for your own purposes. If you do enhance or extend it, please post back here in the comments and let me know what you have done.

The Code is below!

By way of brief introduction to the function, a few explanations are first required. So this is how we will call the function...

If we are specifying the body Struct, we can skip all the other Attributes as we will sending our own custom build design to the fmail tag else you can use the default design of the Mail..

<cfset EmailNow = sendMail(mailto='abc@wal.com',mailcc='abc@wall.com',subject="#Subject#",Option="1")>

or

<cfset EmailNow = sendMail(mailto='abc@wal.com',subject="#Subject#",body="1",contents="#your_custom_table_content#")>

The main purpose of creating this kind of small UDF is suppose you want to have a custom Template layout for all your…
0
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ).

While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aesthetic purposes.  In addition I also wanted to include a result count so that the user would know which set of the results they were looking at out of the total.

It took a bit of searching but I ended up combining a few code snippets and thought I would share the results of my endeavor.  I hope you find them helpful!


Step by step solution:
( skip to the bottom if you want the full source – requires minimal modification )


Step 1:

- Would be to create your <cfgrid> and a .cfc to populate it with some data.

Here is a great <cfgrid> tutorial if you require assistance on creating a <cfgrid> as I will not be covering that here:
http://www.forta.com/blog/index.cfm/2007/5/31/ColdFusion-Ajax-Tutorial-3-Live-Data-Grids

Step 2:

- It is important that the following <script> be placed inside of the <head> </head> tags of your page:
("YourGridName" should be replaced with the name of your cfgrid )

NOTE: You should replace the "showWin" function which with whatever function you want to run as the handler for each button.
<script>
	init=function(){
		//get the grid component 
		grid = 

Open in new window

0
Ready to get started with anonymous questions?
LVL 9
Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

PROBLEM: How to open a cfwindow or run a function on double click of a cfgrid row.


One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items in a sub window. ( I tried posting a question in the forums to no avail and finally came up with my own solution after an extensive session of searching on google )

For something that seems quite simple it would have been nice to avoid that nuisance so I decided to create an article for anyone else who might be looking to do something similar.  At the end of this article I have included a full page source which will require minimal modifications to work ( explained in detail below ).

Step by step solution using CFGrid Event Listeners:
( skip to the bottom if you want the full source – requires minimal modification )


Step 1:
- Would be to create your <cfgrid> and a .cfc to populate it with some data.  It is important that the “selectmode” attribute for your grid be set to “row” ( selectmode=“row”)

Example:
<cfgrid name="YourGridName"
            format="html"
            pagesize="10"
            selectmode=“row”
            striperows="yes"
            bind="…">

Here is a great <cfgrid> tutorial if you require assistance on creating a <cfgrid> as I will not be covering that here:
http://www.forta.com/blog/index.cfm/2007/5/31/ColdFusion-Ajax-Tutorial-3-Live-Data-Grids

Step 2:
1
 
LVL 14

Expert Comment

by:RickEpnet
Comment Utility
Did you ever post on how to do this.
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
Comment Utility
Hi Rick,

I have created a Tutorial on this and Will post it here, it may take some time for Approval

Cheers
0
The technique is by far very Simple!

How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet with you guys how did I do that.   Using a simple technique to make work from query to DOC using Coldfusion:

Here is the coding sample…

In the code below, we are using the component where we are fetching the query results and putting them in the endUsers variable.  Now we run a simple query and below running will generate the code as we expected.

The below code is provided with the HELP of SidFishes (an EE Coldfusion Expert)
<cfset tools = CreateObject("component",".tools")>
<cfset endUsers = #tools.UsersArea()#>
<cfset ExcelFileName = "#DateFormat(Now(), 'mmddyyyy')#.doc">
<cfcontent type="application/msword">
<cfheader name="Content-Disposition" value="filename=menu_#ExcelFileName#">
<cfoutput query="endUsers">
<table cellpadding="0" cellspacing="0" border="1">
   <tr>
      <th>Created By</th>
      <th>Created Date</th>
      <th>Status</th>
   </tr> 
   <tr>
      <td>#endUsers.firstname#</td>
      <td>#endUsers.lastname#</td>
      <td>#endUsers.nemail#</td>
    </tr>
   </table>
</cfoutput>

Open in new window


This may not be the best technique but it works.  Another technique of doing the same is which I tried my way is listed below:

<cfset tools = CreateObject("component",".tools")>
<cfset endUsers = #tools.UsersArea()#>
<cfsavecontent variable="docfile">
<table border="1">
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Email Address</th>
  </tr>
  <cfoutput query="endUsers">
    <tr>
      <td>#endUsers.firstname#</td>
      <td>#endUsers.lastname#</td>
      <td>#endUsers.nemail#</td>
    </tr>
  </cfoutput>
</table>
</cfsavecontent>
<cfheader name="content-disposition" value="inline;filename=ToDoc.doc">
<cfcontent type="application/msword" >
<cfoutput>#docfile#</cfoutput>

Open in new window


That’s Pretty Simple Techniques, try it and You will be amazed to see its results! The technique we presented is far by very basic technique. Although there are many custom tags available which can by far generate good results through the use of CSS and many HTML Tag.  But they are paid ones!

This is the simple technique in which we can generate our result in the doc File!  For quick view.  If you are not really serious about the formatting and want to show it as simple and as fast you can. Try the technique which suits you and enjoy.
2
This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for submitting the forms and also sending response back in the best way which is JSON (JavaScript Object Notation).

    Form

A simple user form which gives the option of entering Name and Email.

 
<CFAJAXIMPORT />
<cfform name="frm" method="post" id="frm"> 
Name:
 <cfinput id="Name" name="Name"   /> 
 <div id="NameError"></div> 
 </div>  
Email Address :
 <cfinput id="emailAddress" name="emailAddress"   /> 
 <div id="emailAddressError"></div> 
 </div> 
 
 <div><cfinput name="submit" type="button" value="submit" onclick="Formsubmition();"></div> 
</cfform> 

<script>
function Formsubmition() { 
document.getElementById("NameError").innerHTML = ''; 
document.getElementById("emailAddressError").innerHTML = ''; 
ColdFusion.Ajax.submitForm('frm','action.cfm', responsecallback, errorHandler);
}
function responsecallback (response){ 
     var errors = ColdFusion.JSON.decode(response); 
     var errorexist = false; 
      
     for(i in errors){ 
         document.getElementById(i+"Error").innerHTML = errors[i]; 
          errorexist = true; 
     } 
   
     if(! errorexist){ 
         alert('Data Inserted');
     } 
} 
 function errorHandler(id, message) {
	
	   alert("Error while inserting\n Error code: "+id+"\n Message: 

Open in new window

2

ColdFusion Language

10K

Solutions

3K

Contributors

ColdFusion is a server-side rapid application development platform originally created by Allaire and now sold by Adobe, implementing the dynamic general purpose CFML programming language. The term ColdFusion is sometimes colloquially used to refer to the CFML language (Cold Fusion Markup Language), but can also include discussions of the server software implementation. ColdFusion runs using a customised version of Apache Tomcat. Earlier versions are bundled with JRun.