Not sure this will help/be of interest but this is what I do.
On my page I set a bunch of eror messages like:
<cfset errorMsgs.userName = "Sorry, the user name you have chosen is already
in use">
<cfset errorMsgs.firstName = "Please enter a first name">
I use jQuery validation plugin with a hack called 'remote' which allows me
to do ajax validation on fields it will benefit (checking user names are
unique for example). So my JS looks something like:
var validator = $('##myForm').validate({
event: 'blur',
focusInvalid: false,
rules: {
userName: {required: true, remote:
'/com/users.cfc?method=remotevalidation&field=username'},
firstName: {required: true}
messages: {
userName: "#errormsg.userName #",
firstName: "#errormsg.firstName#"
}
});
This takes care of client side validation if the user has JS enabled and
gives the benefit of ajax validation on certain fields.
The form is self-referencing (i.e. it posts to itself). Above all the HTML
goodness I detect if the form has been submitted and, if it has, pass the
form structure to 'addUserValidation' function in the user.cfc. This
validates each form field, passing certain fields (such as userName) back to
the 'remoteValidation' function to avoid doubling up code. The function
creates a list of any fields that fail validation which is passed back to
the form page which, in turn, loops through the list and presents the
appropriate error messages (the same ones used for the JS) to the user. If
the fields all validate, the form struct is passed to another function which
performs all the logic (and then basically redirects the user to a success
page). And that takes care of server-side validation.
If the user has JS they get the benefit of real-time validation prior to
submitting the form. If they don't have JS the form submits normally. JS or
not the form goes through the server-side validation.
So far this is working well for me. However there is one major, major flaw.
The only way I could get the ajax to work was to make it syncronous which
freezes the browser until a response is received. Under the circumstances (a
dedicated CMS app on a dedicated server on an internal network) I'm happy
for my client to take that risk :). Otherwise the ajax stuff would be out of
the window until I figure out a way to do it asyncronously.
Cheers!
Gareth
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create Web Applications With ColdFusion MX7 & Flex 2.
Build powerful, scalable RIAs. Free Trial
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJS
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:275632
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4