I've been meaning to build a general purpose form validator, and have
run into an immediate need, so I think I'll work on it. Here's my
thinking:
1. Form fields would be named in some maintainable manner: either
reflect the table and column, the form and field. For example,
<input type="text" name="users.email" value="<@COLUMN "users.email">
size="30" maxlength="255" />
or
<form name="update_user" action="...
<input type="text" name="update_user.email" value="<@COLUMN
"users.email"> size="30" maxlength="255" />
2. I would keep a table of all the form input fields:
table
column
required
validator
format
This would get queried and cached in an app or domain scope array:
form_input_name, for example users.email (concatenated from table and
column
length (from DESCRIBE TABLE)
type (ditto), but this might not be needed
required (yes/no)
validator (a metatag or method that processes the data)
format (a FORMAT attribute to be applied to the variable in the SQL
statement. This is why I need this -- I need to make sure that some
inputs are converted to mySQL date format).
This approach would be if I thought that I could apply the same
validation a column, no matter what form was submitted.
On the other hand, it might be better to use the form.field approach,
because I could then verify that the form was allowed to be submitted
by the user
3. On form submittal, run a method:
a) Save all validly named POSTARGs into witango variables, eg., @@user
$users.email
b) check that all required fields are present
c) trim all saved variables to length
d) apply the validation function.
Now here is the queston: how do I implement the validator? One
approach would be to store witango code in the validator column and
execute that upon the data. Can this even be done? Run-time
generation of witango code?
Or store a validator index in the table and then call a validator
method with the index and the input variable as parameters:
Case 1:
<@ISDATE @@method$parameter>
Case 2:
<@ISNUM @@method$parameter>
Case 3:
<@CALLMETHOD OBJECT=...
Case n:
Anyone have any other thoughts, suggestions?
Thx.
Bill
William M. Conlon, P.E., Ph.D.
To the Point
345 California Avenue Suite 2
Palo Alto, CA 94306
vox: 650.327.2175 (direct)
fax: 650.329.8335
mobile: 650.906.9929
e-mail: mailto:[EMAIL PROTECTED]
web: http://www.tothept.com
________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf