Posts Tagged ‘Coldfusion’

Quick Coldfusion AJAX – Part 2

Saturday, January 9th, 2010
A graphical despiction of a very simple html d...
Image via Wikipedia

Where we left off

If the first part of this short Coldfusion AJAX series, we discussed using the CFDIV tag, along with the CFAJAXIMPORT tag to enable us to dynamically load content into a div (cfdiv) layout container on the fly.  The only custom javascript we made was to create a function that our href called to key the Coldfusion.navigate feature.

This time we will be discussing submitting forms asynchronously using Coldfusion, the CFDIV and CFFORM tags.  This nifty feature allows web developers to submit their form within a containing div, and have the results of that form appear directly back to the user without reloading the entire page.  In part three, the final installment, we will discuss how to build a search suggestion form control that dynamically populates a search text box as the user is typing.

CFDIV and CFFORM tags

We’ve already discussed the CFDIV tag, but now we discuss the CFFORM tag.  The CFFORM tag is specific to Coldfusion and inserts forms into the page with server and client side processing, including built in validation for the tags contained within the form.  Speaking of the tags within the form, they take on special characteristics and names, rather than using the input tag, we will be using the CFINPUT tag.

To ensure the form submits via AJAX we will simply enclose our form within a CFDIV container, keeping in mind that we need to include the proper tags via CFAJAXIMPORT.  The other thing to note is on the CFDIV we are including the the page that contains our form as the bind parameter this time. The listing below is the complete listing for the form, note I have omitted the rest of the standard page elements (head, title, body etc.) for brevity. Provided you have your form handler script setup properly, in this case I called it formprocess.cfm in the example, the form will submit within the div.

Quick Code


<cfajaximport tags="cfform, cfdiv">
<cfdiv id="fomSub" name="formSub" bind="url:form.cfm">
</cfdiv></cfajaximport>


In the form.cfm file we would have the following:

Quick Code


<cfform action="formprocess.cfm" method="post&gt;
&lt;cfinput type=" text="" name="form1" id="form1" maxlength="45" size="20">
<cfinput type="submit" name="submit" id="submit" value="Submit">
</cfinput>
</cfform>
Reblog this post [with Zemanta]

Quick Coldfusion AJAX

Friday, January 8th, 2010
A graphical despiction of a very simple html d...
Image via Wikipedia

External Library?

With Coldfusion 8 and 9, there are a full host of tools that you can use to enahnce user interactions and interfaces in your web apps.  One of those is the built in AJAX features.  While you can program your own, or even use an external javascript libarary, Coldfusion has it’s own, and it is very simple to use, cross-browser friendly and can be implemented in short order.

While you follow the rest of the post, do keep in mind that using the Coldfusion solution present, it does load files from your Coldfusion installation libraries.  These javascript files are sent to the browser just as any other javascript file.  Also remember that this is just one tag in the Coldfusion AJAX library – there are many others that support asynchronous form postings and much more.

Using CFDIV

The first thing you will want to do is import the necessary tag to use the cfdiv layout control.  You can do this by including Quick Code

<cfajaximport tags="cfdiv">

The second thing is to ensure you have a .cfm file with the content you are loading into the cfdiv.  Say for this example we will call it content.cfm.

In your page, you simple call the cfdiv like you would a normal div layout container, with one exception – the bind parameter which tells it which .cfm page to load. Keep in mind, if you need to pass in url parameters, that is fully supported, making it that much more dynamic.

Quick Code

<cfdiv id="myDiv" name="myDiv" bind="url:content.cfm">
</cfdiv>

Putting it together

To really make it work well, let’s show a sample page, complete with a simple javascript function that calls another Coldfusion ajax control, Coldfusion.navigate.  The Coldfusion.navigate function let’s us dynamically load the content into the cfdiv – so we could build a navigation menu and use that to dynamically load the content into our div.

Quick Code


<html>
<head>
<title>Test Coldfusion Divs</title>
<script>
function loadContent()
{
Coldfusion.navigate("content.cfm", "myDiv");
}
</script>
</head>
<body>
<ul><li><a href="javascript: loadContent();">Change Content</a></li></ul>
<cfdiv id="myDiv" name="myDiv" bind="url:somestartercontent.cfm">
</cfdiv>
</body>
</html>

Now, we have a basic page that will load somestartercontent.cfm when the page loads, and when the visitor clicks on the change content link, it will run the javascript function that calls the Coldfusion.navigate function.  This will load the content.cfm page into the myDiv div.  Note the Coldfusion.navigate function takes two parameters in this scenario – the page to load and the div to load it in.

Reblog this post [with Zemanta]

ColdFusion and MSSQL NText Fields

Tuesday, August 4th, 2009
Computer science
Image via Wikipedia

Late last week I was working on some new changes to PBR’s web site (my employer) and ran into a nasty snag of an issue. I was pulling data out of a table, and for an exceptionally strange reason, seemingly random HTML kept appearing in the source code. Needless to say, this HTML was breaking the layout I had been working towards and boggled not only my mind, but our SVP of IT’s mind as well.

In the end, we ended up changing the field type as it was held in the Microsoft SQL database. The field was originally set to be an ntext field, and we changed it to a varchar field, as it really had no purpose being an ntext field in the first place, but that’s another story. After we made the change, we did lose some data on the resulting trimming of the data field, however the parts that were trimmed were already migrated to another field, so big loss.

As soon as we changed this, the HTML injections ceased. What happened? I have put some sample code below to illustrate it.

What the code should have came out to be.

Quick Code


<div id="myDiv">
     <p class="indentClass">
          My content was coming out of the db here
     </p>
</div>

What the code actually came out to be before we changed the field type.
Quick Code


<div id="myDiv">
     <p class="indentClass">
          </p>
      <p>My content out of the db here</p>
      <p></p>
</div>

You can see that my opening paragraph tag was automatically closed, a new one started and closed after the database content was published, and an empty paragraph added at the end.

Now it is possible that the site, with the many thousands of pages and hundreds of thousands of lines of code specified this in a CFC or CFTAG file – in other words it was tied to the field name/type to force the HTML output, but I could not find it anywhere.

Any thoughts or experience you may have on this? Share them in the comments.

Reblog this post [with Zemanta]

Been A While – .Net Coldfusion and More

Tuesday, June 30th, 2009

.Net Code Snippet

.Net Code Snippet

Obviously, it has been a while since I have posted on my blog. Quite simply after starting my full time employment contract I have not had time. Why? I am working long hours doing many new things – such as programming in Coldfusion and .Net.

I took on a position of web developer and have now setup 2 Linux servers, coded a C# .Net app from the ground up and am looking at major site updates using Coldfusion. While entertaining, fun and challenging, it has meant a bit longer days at work than I had anticipated – however I am NOT complaining in the least amount. I have a full time job and am paying bills and getting caught up on things. That’s always good!

The past week and a half has brought more changes – I was told we are going to look at revamping the entire site and work and will be doing it in VB.Net, so more learning, which is one of the things I love most about IT and web development – the constant learning, expanding and maintenance of knowledge. With that, we are looking at making it easier to get content out, expanding on and integrating more with social media and getting an infrastructure in place that will allow forward motion, expansion and easier maintenance. This also means a more enhanced visitor and site user experience, which is always something that is highly important.

The other thing of note, is that I will try my best as I go through Coldfusion and .Net programming to get some tutorials, how-to’s and other related posts up on those subjects. I will be learning quite rapidly and am sure to have some struggles to fight through, and those are the items I would like to post about.