Definitely possible. I've built a product very similar
(http://www.electricsheep.co.nz/terraform/). If I were you I'd consider
using XML to store all the form field validation data in one packet at the
top of the form or something like that. Of course that would effectively
restrict you to CFMX only. I'd recommend adding a caption to the fields too
- a human friendly version of the field name. And I'd definitely consider
adding regex validation + the ability to add a catchall custom error message
for each field.

-----Original Message-----
From: Austin Govella [mailto:[EMAIL PROTECTED]
Sent: Thursday, 12 February 2004 2:06 p.m.
To: CF-Talk
Subject: Custom tag for data validation - tell me if I'm crazy

I'm working on a modular way to validate form data and
display error messages across all of my applications.

Once a form is submitted, I want to:

1. Make sure the form data meets certain requirements
(required, alphanumeric, whatever...).

2. If there's an error, redisplay the form with the original
responses filled in.

3. Highlight the field that had the errors.

4. Display the error messages *near* the field that had the
error.

So, my proposed solution uses a custom tag, cf_validate,
that requires two attributes, the variable and the variable
name. A number of optional attributes indicate how the
variable needs to be tested. For example, to validate the
form data for form.foobar:

<cf_validate
VariableName = "foobar"
VariableValue = "#foobar#"
Required = "yes"
StringType = "alphanumeric">

If there's an error we set three variables:

1. caller.form_type = "error"
2. caller.foobar_class = "error"
3. caller.foobar_message[] = "error message"

Form_type is a flag that tells us to redisplay the form
(instead of inserting/updating the record).

My form elements are set as list items, so Foobar_class sets
the class to <li class="error"> (so I can visually note the
error).

And the array, foobar_message[], displays any existing error
messages. I'm planning on looping through the array and
displaying them in a numbered list so the user knows exactly
how many ways they suck.

So, on my whiteboard, it looks like it works, but that's a
lot of code and debugging to go through for it to end up not
being possible. Am I missing any big obstacles? Is it
categorically impossible?

Many thanks for the guidance,
--
Austin

  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to