Hi Cliff,

Thanks for the feedback. Am afraid mach-ii is out of the question (I'd love too, but I can't ... sigh) so I'm stuck with your four point plan below:

(1) Taking your form data and an instance of the bean and populating it with the form data,

Right - can do this, Display form post to Action form. Action form creates FormValidator object and call validate.

  (2)  Calling the validate method and handling the result appropriately,

Again - not a problem. If validate is true complete action. If validate is false ... not sure here?

  (3)  Providing for a quick way to preserve state of the form when an
error message occurs, making sure the user doesn't lose the data they
entered into the form,

Not sure about this - Am guessing I could throw the contents of my FormValidator.cfc as form parameters to the Display form?

  (4)  Displaying error messages appropriately

Bit lost here - How could I make each form control know it was invalid and output the error string.

Apologies if these seem like stupid questions but in asp.net pages postback to themselves automatically and preserve control state. I just drop a validator on the page, tell it which form control to validate and bingo, I'm done. I miss that. A lot :)

Cheers, Pete  (aka lad4bear)




<br><br><br>----Original Message Follows----<br>From: Cliff Meyers &lt;[EMAIL PROTECTED]&gt;<br>Reply-To: [email protected]<br>To: [email protected]<br>Subject: Re: [CFCDev] Form Validation<br>Date: Sat, 7 May 2005 14:19:06 -0400<br><br>In Mach-II, there is the notion of writing a &quot;bean&quot; CFC that models<br>your form data and also does validation on it. I like the idea of<br>creating an object that has properties that map to all my form fields,<br>and then writing a single validate() method on the CFC that contains<br>all of the data validation logic. It bundles all of the code about a<br>form together in one place instead of spreading it out all over and<br>making it difficult to maintain.<br><br>Jon Block's Bean Creator is a great tool for quickly generating the<br>CFC code for your bean:<br><br>http://cf2.jonathanblock.com/bean.cfm<br><br>Once the bean is created, you can write all your data validation logic<br>inside the validate() method. Depending on how your application is<br>structured, you really just need to provide for a few things:<br><br>(1) After the form is submitted, get your form data into the bean<br>using the various set methods,<br><br>(2) Perform your validation<br><br>(3) Do the calculation<br><br>(4) Redisplay the form to the user<br><br>In a more traditional app, you'd just do #1 and #2, and then based on<br>whether validate() returns true or false, either continue with your<br>app flow (writing to the DB in most cases) or generate an error<br>message and redisplay the form to the user. Here you're introducing a<br>few new steps, but this isn't uncommon since many, many applications<br>have the user submit the form, redisplay the data so they can verify<br>it's correct, and then &quot;confirm&quot; to save their data.<br><br>If you don't want to use Mach-II or already have your own framewor,<br>all you really need to do is write a few CFCs to help you with a few<br>things...<br><br>(1) Taking your form data and an instance of the bean and populating<br>it with the form data,<br><br>(2) Calling the validate method and handling the result appropriately,<br><br>(3) Providing for a quick way to preserve state of the form when an<br>error message occurs, making sure the user doesn't lose the data they<br>entered into the form,<br><br>(4) Displaying error messages appropriately<br><br>This is a topic very near and dear to my heart because I HATE form<br>validation :) Apologies if my response was long winded or not what<br>you're looking for...<br><br><br>-Cliff<br><br><br><br>On 7 May 2005 16:33:54 -0000, [EMAIL PROTECTED]<br>&lt;[EMAIL PROTECTED]&gt; wrote:<br> &gt; This may not be the answer you are looking for, but I had a similar code seperation<br> &gt; problem this week.<br> &gt;<br> &gt; I needed to calculate some numbers and display them<br> &gt; BEFORE they were saved to the database. I didn't want to write the display<br> &gt; calculations in javascript and the database calculations in coldfusion. I<br> &gt; wrote cfc methods to do the calculation, and them used those methods for both.<br> &gt;<br> &gt; I used some XMLHTTPRequest stuff (Ajax) to call a coldfusion script that<br> &gt; invoked the calculation functions, and then returned the result to the browser.<br> &gt;<br> &gt; When the data was saved, I again called the calculation functions, and stored<br> &gt; the results.<br> &gt;<br> &gt; It may sound like alot of work, but I only wanted the calculations<br> &gt; in one place to prevent the two sets of code from getting out of sync.<br> &gt;<br> &gt; It wouldn't be too difficult to put all your form validation into a function,<br> &gt; and then pass the form contents to the server via a similar method, displaying<br> &gt; the validation results before they ever submit the form.<br> &gt;<br> &gt; This may not be<br> &gt; what you were thinking of at all...<br> &gt;<br> &gt; -Sam Curren<br> &gt;<br> &gt; --- [email protected]<br> &gt; wrote:<br> &gt;<br> &gt; Hi guys,<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt; This may be a little of topic but possibly not. With<br> &gt; regards to form<br> &gt;<br> &gt; &gt; validation, client side validation is helpful but can<br> &gt; be side-stepped as can<br> &gt;<br> &gt; &gt; the use of hidden fields, so logically this makes<br> &gt; server side validation a<br> &gt;<br> &gt; &gt; neccessity. Consequently my code ends up riddled<br> &gt; with validation logic; is<br> &gt;<br> &gt; &gt; it the right type, does it fit in a range, does<br> &gt; it match a pattern etc. Is<br> &gt;<br> &gt; &gt; there a design pattern I could use that would<br> &gt; make doing this sort of thing<br> &gt;<br> &gt; &gt; cleaner or possibly a server-side validation<br> &gt; library / cfc available to help<br> &gt;<br> &gt; &gt; with this?<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt; Cheers, Pete (aka lad4bear)<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt; ----------------------------------------------------------<br> &gt;<br> &gt; &gt; You are subscribed to cfcdev. To unsubscribe, send an email to [email protected]<br> &gt; with the words 'unsubscribe cfcdev' as the subject of the email.<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt; CFCDev<br> &gt; is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt; CFCDev is supported by New Atlanta, makers of BlueDragon<br> &gt;<br> &gt; &gt; http://www.newatlanta.com/products/bluedragon/index.cfm<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt; An archive of the CFCDev list is available at www.mail-archive.com/[email protected]<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; &gt;<br> &gt;<br> &gt; ----------------------------------------------------------<br> &gt; You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.<br> &gt;<br> &gt; CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).<br> &gt;<br> &gt; CFCDev is supported by New Atlanta, makers of BlueDragon<br> &gt; http://www.newatlanta.com/products/bluedragon/index.cfm<br> &gt;<br> &gt; An archive of the CFCDev list is available at www.mail-archive.com/[email protected]<br> &gt;<br> &gt;<br><br><br>----------------------------------------------------------<br>You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.<br><br>CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).<br><br>CFCDev is supported by New Atlanta, makers of BlueDragon<br>http://www.newatlanta.com/products/bluedragon/index.cfm<br><br>An archive of the CFCDev list is available at www.mail-archive.com/[email protected]<br><br><br>





---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]




Reply via email to