Months Archive May 2007

 
 

Validation, Business and Functional

The recent discussion of Form Validation – How do you do it?, had me wondering just what might be involved in creating an easy to use validation framework. It’s a task that might seem easy, but when you get down to all the special cases it’s anything but. ColdFusion is a language designed around rapid development, so why not attempt to create a Validation framework modeled around the idea that new rules can be added easily? Ok, that’s probably the case with any such framework, but it should be easy for a dynamic here. Today I’m mostly just brainstorming what I’d want and possible implementations. Over the next few days I’ll try to implement this.

So what should it be able to do? Well, Jeff’s post stated some very important requirements that I’d say are all must haves. To reiterate some of the points though, it should be able to validate entire business objects (cfcs with getters/setters OR named structs), it should be able to have a “strict” mode where it validates everything or a mode where only set fields are validated. It should be able to validate forms via ajax (funcational validation), as well as single fields via ajax. It should also be able to validate from the client side and return error messages (json/html) or validate on the server side and get back some sort of error collection.

We want this to be as easy to use as possible, so the validation rules should only exist in a single place. The ajax features should also automatically call the associated validation rules. One of the difficulties with ajax is always that it requires twice the work by definition, but what if by some convention both Javascript and validation could be written for us? Here’s what I’m talking about.

<form id="register" validate="onsubmit" message="before">
   <div class="group" id="required">
      <span id="register-first_name-field">
         <label for="register-first_name">First Name</label>
         <input type="text" id="register-first_name" name="user[first_name]" />
      </span>
      <span id="register-username-field">
         <label for="register-username">Username</label>
         <input type="text" id="register-username" validate="onkeyup" name="user[username]" />
      </span>
      <span id="register-email-field">
         <label for="register-email">Email</label>
         <input type="text" id="register-email" validate="onchange" name="user[email]" />
      </span>
   </div>
   <span>
      <input type="submit"/>
   </span>
</form>

This basic form would be the basis for how the front end would work. Based on the metadata we’re marking up on the form (namely those “validate” attributes). The idea is that a form has basic validation rules associated with it — when to validate it and where to put the return values. Each field in the form would then inherit the validation rules defined in the form, but could also overwrite them. For instance, this form would validate everything on submit by default, and place and error messages “before” the field they’re for. Other options might include “after”, “top” or “bottom” for the very top of the form, or “above” and “below” for errors to be put at the top of the current grouping. The HTML will require some kind of hooks for where to place these messages of course, which is where some the convention markup comes into place. The before/after messages would look for the formid-fieldid-field element and place it in an element before that. Top/Bottom would look for the formid and place based on that, and the grouping option would look for an element with the class of group that’s a parent element.

Now how would this know where to submit to for validation? That’s another easy convention to handle. Let say there’s three possible things that can be validated via ajax on a form — an entire form, a single object from a form or a single field from a form. Creating URLs for these to submit to might end up with something like this:

http://localhost/validate (validate.index)
http://localhost/validate/object (validate.object?object=objName)
http://localhost/validate/object/field (validate.field?object=objName&field=fieldName)

Using Coldcourse you could create these without much trouble, and the javascript could discover the validation URL to use based on the form field names. The fields are named in the form object[field] which is a Ruby on Rails/ColdFusion on Wheels convention. On the server side these are converted to structures before we ever have to start working with them. This validate controller would then call up some sort of ValidationService where the real meat of the work happens. The controller then knows to return the errors it gets back to the javascript handler based on some sort of Javascript view template.

This is just brainstorming at this point, but looks easy enough to implement. If there’s anything I’m overlooking, or any suggestions with this so far feel free to comment.

Tomorrow: start planning the service layer!

Make Your Blog Easily Readable in 1 Hour

There’s one thing that usually bugs when trying to find new blogs to read and that’s a lack of direction. A lot of the time the user interfaces we take for granted in the often read blogs are far from utilized elsewhere (I admit I’m guilty of some things as well). Do you ever go to a new site only to have no idea what the main focus of the blog is about? Or perhaps it’s so varied that you can’t tell what their specialties are and what they’re just getting into? Or worse yet most posts stray from topic to topic with seemingly no real glue holding them together. Well, before applying over at 9 Rules getting as many of the easy things out of the way as possible was one of my main goals. These are also the kind of things that help with search engine optimization as well. These aren’t hard things to do, but they’re often overlooked.

Title and Subtitle

The title of a site won’t matter much. If you’re hardcore SEO this is more important of course, but for humans it can be made up words, gibberish, anything — as long as it’s unique. The subtitle though helps out almost as much anyways, and that’s where you can put the real focus of your site in the forefront.

Have an Intro

Of course I don’t mean a flash intro, but a quick intro on the side of the homepage describing yourself is a great way to go for single person blogs. Often for more community driven blogs you can still have an intro about the site as well. This can usually link into an about page with more details..

About Page

Easiest thing in the world. Not a bad idea to post a picture either if you have one that’s slightly above decent. This helps bring in some credibility and can clarify background on where you’re coming from.

Tag Cloud / Category List or Cloud

Being able to see what you’re most interested in is never easier than with a sized tag cloud or a category cloud. A category listing with numbers is also a great help. Listing every single tag can backfire though if you’ve heavily tagged your posts.

Related Posts

Showing related posts not only gives the users a few on topic suggestions, but it also helps build credibility that you’ve thought about the topic a little more. For someone new to your site this helps them read more about whatever brought them there in the first place.

SES URLs

If you’re using Wordpress, this is as easy as changing a setting. This is one feature that seems to be becoming increasingly important lately. There’s something more professional in a URL that ends with a path rather than a string of text as parameters. This isn’t a make or break item, but if your blogging software supports it, why not use it?

Keep URLs the same

Once you get with something, stick with it. On this blog I’ve been changing the layout on a weekly basis trying to find something that works and that I can elaborate on. In that time, however, all the URLs and the main content on them remained the same.

Sitemap

Recently Yahoo, Google and MSN all decided to use the same sitemap format. There’s also a Wordpress plugin to do this for you automatically. This is one thing you can setup and forget completely about. If you’re curious though, they look like my sitemap.

Easy on the Ads

If there’s one thing I can’t stand is a blog loaded down with ads. I can understand wanting to pay for hosting, but I doubt most people are making enough on ads to make things worth it. The techniques used to make the most money from ads probably aren’t the tactics you want associated with you anyways (unless you’re running a “making money from ads” blog ;) . There are much nicer looking ways of making money from ads anyways, such as Text Link Ads, or referring people to a webhost that pays referrals such as Dreamhost or just linking to products on amazon occasionally with your referral code. I’m sure there comes a time when even Joel on Software and Coding Horror will have ads, but they’ve managed to do pretty well without them.

Post, Post, Post!

Regardless of everything else, content is king. If you’re an amazing writer with a barebones site (as with those last two links), people will come. Just writing about what you know and writing about what you learn is enough for most people. If you have something to say, don’t feel shy about saying it.

There are books and books on search engine optimization you can read, but unless you’re making a career out of it one may do the job. So many of the things that make your site more usable for a person also help with SEO anyways. Almost everything on here can be setup and then completely forgotten about, leaving you to just worry about writing.

Creating Top Level User URLs with Coldcourse

Someone asked me the other day if it would be possible to create URLs where a users username was the first thing in the URL. Something like http://localhost/AdamFortuna for example. This is usually a problem because any rules defined as such would usually conflict with your default controller, making the previous link go to the action AdamFortuna.index by default. With Coldcourse, Rails and CF On Wheels (where Coldcourse comes from) there is an easy way around this though, although it does involve repeating yourself a little.

Coldcourse runs through all listed courses and picks the first one that matches. The trick to handling users in this method is to create routes for all other controllers, then at the end have a course to match all users. To put it in coding terms, it would look something like this.

[cfm]


controller="user",
action="profile" )>
controller="user")>[/cfm]

There may be some flaws in this that I’m not seeing right away, but it seems like a simple enough solution. Of course this would be much easier if you instead wanted URLs similar to http://localhost/user/AdamFortuna. That way you wouldn’t need to list out your controllers, instead you’d be safe with just one blanket rule.

[cfm]
controller="user",
action="profile" )>
controller="user")>[/cfm]

The actions like blog, friends, profile would work by default, although anything outside of the user controller you’d have to add in specific rules for.