Thor can now also handle client-side validation

Apr 08, 2009

I just updated my CFC based validation system called Thor with a jQuery example that shows how it can also handle client side validation.

Thor already does a solid job of validating user data on the server-side, but you may still need a solution for client-side validation. This can be difficult for many developers because it may require using two different validation systems. This means doubling the code to get any basic form up and running. And again, this can be difficult to manage and maintain.

Thankfully with some basic jQuery scripting, you can now make Thor handle client-side validations. One of the examples (should be Example 9) included with the Thor zip is one which handles client-side validation with the use of the popular JavaScript library, jQuery. The jQuery code will dynamically determine the form input elements on the page. As a user enters data in that input element and then tabs over to the next item, jQuery will do a simply POST call to ColdFusion which will then route that input data through Thor to see if it's valid. If it isn't, it will respond with the proper error code which jQuery will then display for the user.

This continuous client-side validation can be very handy if you have large html forms where it takes several minutes for the user to enter all the data. As they go through the process of entering data, they discover in 'real-time' if there are any problems. When the users gets to a submit button, they can be fairly certain that most if not all the data they have enter is correct. This can make the experience more enjoyable for the end user.

This process however can be very server chatty. So feel free to let me know how to it scales for your applications. The benefit of this is it's very easy to add on client-side validation and  you can now  have just one set of validation libraries that can handle both client and server side validation. There's no other ColdFusion based solution that I'm aware of that can handle this.


Bob Silverberg

Bob Silverberg wrote on 04/12/097:48 PM

In response to "There's no other ColdFusion based solution that I'm aware of that can handle this", actually there is. Check out

It takes a different approach to validations than Thor. One of its main features is that it generates both client-side and server-side validations from a single piece of metadata.
John Mason

John Mason wrote on 04/14/095:30 PM

Cool, sorry I missed that. So it looks like your metadata generates the server and client validators. On the client side your using jQuery validator plugin?

I didn't want to get restricted by just having regex, specially on the client side so in Thor the calls can be handled directly. It's more server chatty than your method but we're basically trying to solve the same problem, not having two different sets of libraries to deal with. Fun stuff :)
Bob Silverberg

Bob Silverberg wrote on 04/14/0910:30 PM

I have written a client-side implementation using the jQuery validation plugin, as well as a scaled down implementation using qForms for an older site. The framework is designed to support multiple client-side implementations. Don't want to use jQuery? Just write a new implementation and plug it in!

I'm not sure what you mean about being restricted to just having regex, my jQuery implementation supports many different validation types. I wanted the client side stuff to actually run on the client, rather than issuing numerous ajax calls, so that's how it's written. Your approach of using ajax to route validations through Thor is good in that you have less code to maintain - just a different approach.

Definitely an interesting problem to tackle.

Write your comment

(it will not be displayed)