cfUniform is a ColdFusion custom tag library that makes adding validation to your forms a snap. The fact that it writes (most) validation for you based on attributes you put in the tag makes it worth using for that feature alone in my mind. However, the benefits don’t stop with validation. It also styles your form fields, labels, hints and error messages for you. Since you can configure a link to a CSS stylesheet in the configuration for the custom tag, you can skin the output generated by cfUniform to match your site’s look and feel.
Best of all, its REALLY easy to get started with. The example below assumes that you’ve put /tags and /commonassets folders from the distribution file in the root of your web site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<cfimport taglib="/tags/forms/cfUniForm" prefix="uform" /> <div class="cfUniForm-form-container"> <uform:form action="someFile.cfm" id="loginForm" submitValue=" Log In " loadjQuery="true" loadValidation="true" loadMaskUI="true" loadDateUI="false" loadTimeUI="false"> <uform:fieldset legend=""> <uform:field label="User Name" name="username" isRequired="true" type="text" hint="Enter your user name." /> <uform:field label="Password" name="password" isRequired="true" type="password" hint="Enter your password." /> </uform:fieldset> </uform:form> </div>
If you’re like me, you’ve probably got a “pet” folder structure that you use for your projects and they typically don’t have the folders /tags and /commonassets hanging off the root. The developers foresaw this quandary and included the facility to pass in a structure containing configuration keys that point the library to the location of various files in the web structure. This is one of my favorite features because it allows me to compartmentalize the library into whatever part of my folder structure I want and then pass in the configuration values. It also makes it very easy to configure a config object in ColdSpring using a MapFactoryBean (remember talking about those a couple weeks ago in this post?) so that you reuse the same configuration object every time you use the library throughout your application.
I’ve not gone into a great amount of detail here on how to use the many features of the library because the developers have a well-rounded set of examples already published. There you’ll see the directions for how to set up a MapFactoryBean config object in ColdSpring as well as all the other form field options that you have in the framework.