Posts Tagged ‘OOP’

Learning CFWheels – form handling and data validation

July 21, 2010 4 comments

I have continued with the CFWheels screencast tutorials in building forms and handling form data.  The focus today was on form validation.  CFWheels has some really cool methods to handle the data after form submission.  Using the validatesPresenceOf() in a model CFC, we can ensure required fields have been entered.  Simply pass the required fields to the method and if there are errors, the hasErrors() method with evaluate to true and the save() method will not insert data to the DB.  The just execute the render() method to get back to the form.  Add a call to the errorMessagesFor() to the form view and a nice bulleted list of errors is displayed along with the form.  The form fields with errors is now wrapped with <span class=”field-with-errors”> allowing us to use some CSS to make the errors stand out.  All done with very minimal code.  Coding this took maybe 10 minutes and about 30 total lines of code.  In spaghetti code this would take me at least 30 minutes and would have been considerably more lines of code.

It’s late now, but what comes to mind is overriding the error messages that are generated automagically with messages that mean more to the user.  So instead of saying, “ysnSubscribe is required,” the error message reads “You must choose one of the subscribe options.”  I’m sure there’s a relatively simple way to do this but it’s late so it will have to wait until tomorrow.  I will say, however that I am pleased so far  with how simple some of the more routine coding tasks become with CFWheels.


Learning CFWheels

July 16, 2010 1 comment

I have a little bit of free time before I start my new job, so I’m doing some learning on my own.  Object-oriented programming, OOP, is something that always eluded me.  It always seemed so abstract.  I did study computer science in college so that may have something to do with it.  Additionally, all the OO discussions I’ve heard within the CF community seemed to assume you had a foundational background already, so I could never quite grasp it.  Model-Glue, Mach-II and other frameworks all seemed to be geared toward those with a solid background already. The documentation was always way beyond me.  So I was hesitant when I heard of CFWheels.  Unlike other frameworks, the documentation here is quite extensive and easy to follow…at least it is so far.  I’m going to give it a shot and see if I can learn something.