CFShopkart - Free Open Source Coldfusion Shopping Cart
Open Source eCommerce

Some Free Coldfusion Code

I have some Coldfusion code that you might find useful in your projects. These are some functions and things I developed for some projects I worked on and they are free and open source.

Free Coldfusion Components

dbqueries.cfc - Database insert and update function.

I developed dbqueries.cfc when I was working on the style editor for CF Shopkart. The CFC included in the latest version is really only used for updating the one table. I have used this cfc in a couple other applications I worked on and it has helped me save time developing. I realize that Coldfusion has CFINSERT and CFUPDATE but the tags are limited and from what I have read there are some security issues. So most developers are now writing CFQUERY statements to do their inserts and updates (you are, aren't you?). This usually involves creating a table, then a form, and then creating your CFQUERY inserts and updates. Here is where dbqueries.cfc comes in handy. Using this you can quickly update or insert something into your database table, and what is great about it is, if you add to your form and table, you don't have to edit any CFQUERY statements.

It works like this:

You create a table in your database to store some data (like contact information). Then you create your form and give your form fields the same names as your column names in the table (just like CFINSERT and CFUPDATE). Then, intead of writing out your CFQUERY statements, you just use CFINVOKE to call the function like this:

<cfinvoke component="dbqueries" method="insertdata" returnvariable="outputmsg">
<cfinvokeargument name="tablename" value="contacts">
<cfinvokeargument name="dsn" value="yourdsn">
</cfinvoke>

This is a simple insert command. What will happen is dbqueries.cfc will look at your form fields and match them up with the columns in your database and builds the CFQUERY statement for you and execute it.

For updates, you just do the same thing except pass in any WHERE statement you want.

<cfinvoke component="dbqueries" method="insertdata" returnvariable="outputmsg">
<cfinvokeargument name="tablename" value="contacts">
<cfinvokeargument name="dsn" value="yourdsn">
<cfinvokeargument name="wherestring" value="WHERE id=1">
</cfinvoke>

Download | Sample

validation.cfc - Form validation function.

I developed this cfc to make form validation on some of my projects a little easier. This returns a query with the fields in error and the error messages that you supply it. You can use this to validate required fields, email addresses, password/confirmation password, Captcha using cfimage tag, and dates. There is another method included for validating states that could be used to validate any entry against a list of values, but for most developers, the required fields method will be the most useful.

In your form add hidden form fields to tell the cfc what is required.
<input type = "hidden" value="firstname|Enter your firstname please;lastname|Enter a lastname please" name="validate_require">

Then at post you will invoke the cfc.

<cfinvoke component="validation" method="validate" returnvariable="qValidation">
<cfinvokeargument name="fields" value="#form#">
</cfinvoke>

See the comments in the cfc and in the sample file to see how to use the other methods.

Download | Sample