One of the areas in which Blackstone should (I won’t say “will” until we ship as stuff could always change, so “should”) make our lives considerably easier is form field validation. I mentioned input masking a few days ago, and
But that is not all, in Blackstone we also plan to simplify client-side and automatic server-side validation. But first, a review of how these are done right now.
Server-side validation is not optional, as already said you must never rely solely on client-side validation. Server-side validation can be as simple as a bunch of
ColdFusion uses the hidden field as a validation instruction, and if login is not specified (in this example) the error message “Login is required!” would be displayed. This functionality has been in ColdFusion since the very early days, and a variety of validation types are supported. The upside of this feature is that the validation rules are within the form, as opposed to on the action page, and this makes keeping the rules and forms in synch much easier. The downside is that they are not failsafe (it would be possible to submit forms without those hidden fields), and there is limited control over how error messages are displayed.
Client-side validation is designed to make the experience better for the end-user. It must never be relied on as the only validation mechanism, but being able to trap errors before form submission does make for an improved user experience. ColdFusion supports client-side validation using JavaScript. While many users write their own JavaScript validation, ColdFusion has long been able to generate basic JavaScript validation code for you. (And although some ColdFusion developers stay away from
In addition to the “required” flag,
Thus far is what is supported in ColdFusion today. So, what does Blackstone change? Well, several things.
For starters, lots more validation types are planned, including the oft requested email and url.
In addition, the JavaScript error message that is displayed when using client-side validation will display all validation errors at once, not just the first.
But perhaps more importantly, it should be simpler to perform both client-side and server-side validation at once.
And the best part is that validation methods may be mixed. So, to validate on the client and server you could do the following:
Here validateAt is specifying both onSubmit and onServer, and so ColdFusion will both generate client-side validation code, and embed hidden form fields for server-side validation.
Pretty cool stuff.
Leave a Reply