ColdFusion

Preserving carriage returns when displaying textarea content

When displaying textarea content on a web page carriage returns are ignored resulting in the content appearing on a single line. In ColdFusion to ensure the content appears as intended you can replace carriage returns with BR tags like so: REReplaceNoCase( your_form_field, "\r", "<br />", "all" ) ...

Published: Thursday 16 February 2012 | Comments: 2 | Read more »

ColdFusion Regular Expressions (REGEX)

Persisting form data as JSON

I recently worked on a project where I needed to store a large amount of data from a questionnaire in a database. My initial approach was to create a table with fields corresponding to each of my form fields. However, this resulted in a large unwieldy database table and some fairly complex code to process my form. If you need to be able to search or manipulate form data at a later date this is ...

Published: Tuesday 14 February 2012 | Comments: 2 | Read more »

ColdFusion

My new year's resolutions for 2012

Beyond making an effort to be happier, nicer to people and less stressed I am not a big fan of new year's resolutions. However, from a programming point of view, there are a few things I plan to do this year. I've listed them below so I can review my achievements (or lack of) in a year's time. Read the following books which I purchased recently from Sitepoint: jQuery: No...

Published: Sunday 01 January 2012 | Comments: 0 | Read more »

ColdFusion HTML jQuery CSS

Importing data from a spreadsheet to a database table using ColdFusion

I'm currently working on a project where I need to import a list of products from a spreadsheet into a database table. Here is the ColdFusion script I have writted to complete the task. <!--- read the spreadsheet data into a query object ---> <cfspreadsheet action="read" src="#ExpandPath( './data.xlsx' )#" query="importdata" headerrow="...

Published: Friday 23 December 2011 | Comments: 2 | Read more »

ColdFusion

Converting a string to title case in ColdFusion

The following function takes a string and converts it to title case. <cffunction name="titleCase" returntype="string" output="FALSE"> <cfargument name="str" type="string" required="TRUE" /> <cfset var newstr = "" /> <cfset var word = "" /> <cfloop list="#arguments.s...

Published: Thursday 22 December 2011 | Comments: 9 | Read more »

ColdFusion

ColdFusion ORM paging in FW/1 (Framework One)

Firstly, in your Handler add maxresults and offset keys to the RC structure and give them some default values. Maxresults is the number of results to be displayed per page and offset is the number of rows to skip. For example, if the value of both maxresults and offset is 10, records 11 to 20 will be displayed. By default we'll want the value of offset to be 0, but you can set the value of ...

Published: Monday 05 December 2011 | Comments: 0 | Read more »

ColdFusion FW/1

Integrating Gravatar with your blog

Today I integrated Gravatar with my blog so, for commenters who have a Gravatar account, you'll now see an avatar next to their blog post comments. As long as you have a commenter's email address it's very easy to display their avatar. In Coldfusion simply convert the commenter's email address to lower case, hash it, convert it to lower case again and add it to an IMG ta...

Published: Friday 02 December 2011 | Comments: 3 | Read more »

ColdFusion HTML

Simple CRUD using CFGRID

I'm currently working on a project where my client needs to be able to create, read, update and delete records in a table displayed on a web page. In ColdFusion CFGRID solves this problem and here's a simple example using the CFARTGALLERY sample database that comes with ColdFusion 9. Firstly, create an Artist.cfc file containing the following code. <cfcomponent output="FA...

Published: Wednesday 05 October 2011 | Comments: 3 | Read more »

ColdFusion

Replicating Jira's time tracking functionality in ColdFusion

I've been working on a project where I wanted to replicate the time tracking functionality used in Jira. Jira allows you to enter a time period in the format of "4d 12h 30m" (4 days, 12 hours and 30 minutes) which, behind the scenes, is converted to seconds and stored in a database. For the purpose of my application I also need to take into account the number of working hours per ...

Published: Thursday 29 September 2011 | Comments: 3 | Read more »

ColdFusion Jira

Converting an array of entities to a list in ColdFusion 9

The following sample code shows how to convert an array of entities to a list in ColdFusion 9. // load an array of category entities categories = EntityLoad( "Category" ); // convert the array to a query categories = EntityToQuery( categories ); // output category titles as a list writedump( ValueList( categories.title ) ); ...

Published: Tuesday 27 September 2011 | Comments: 0 | Read more »

ColdFusion