[Catalyst] Form validation in insert() and update()?

John Napiorkowski jjn1056 at yahoo.com
Thu May 17 00:28:37 GMT 2007


--- Jason Gottshall <jgottshall at capwiz.com> wrote:

> Chris Laco wrote:
> > Off Topic. Making a note for myself and
> DBIC::Validation
> > 
> > 100 can be validated because we have %colinfo
> {size => 100}
> > Patterns could be covered in validation_profiles
> at the source
> > level...but maybe this would be nice as well:
> > 
> >   {
> >     type => 'VARCHAR',
> >     size => 100,
> >     validation => qr/\@{1}/
> >     #validation => sub{}
> >   }
> > 
> > 
> > /me urns for better validaiton profiles created
> from DBIC %colinfo
> 
> This gets at precisely the issue I've been wrestling
> with lately.
> Validation constraints at all levels (db, model,
> controller, form, etc.)
> seem to sort themselves into two general categories:
> field-specific
> questions ("Is it required/unique?", "Does it match
> a given pattern?",
> etc.) and broader domain-level interdependencies
> ("Require at least one
> of the following...", "If A is 'foo' then B must
> match /^bar|baz|qux$/",
> etc.) This leads me to want to define those
> constraints in different
> places. 
> 
> For example, I'd love to be able to define
> per-column validation
> patterns/subs at the DBIC level as Chris describes
> above, and then
> utilize that meta info to validate input at higher
> levels (model,
> controller, form) as MST described in another post
> on this thread. But
> I'd also need a way to create a profile for, let's
> say, form field
> validation interdependencies (which can be
> independent of
> domain/model/db-level interdependencies, as
> previously noted). But how
> do I implement a concise way of accomplishing all
> these things?
> 
> Or is the fact that I have so many things to worry
> about an indicator
> that this isn't going to be concise?
> 
> If Chris were to implement a per-column profile
> option for
> DBIx::Class::Validation, I'd be inclined to look for
> a way to use
> Data::FormValidator at several levels. Would it make
> sense to have a
> method that would compile everything from %colinfo
> and
> validation_profile() into a single profile that
> could then be utilized
> (and modified/extended) at the model/controller
> level?

I was thinking something similar.  We could have an
optional DBIC::Validation::Auto that would create a
base profile based on the columnn metadata, like
required, unique, must be FK, etc.  Then your custom
profile would be automatically merged in.  Would be
useful to help CYA at the physical model level. 
However you still need to do checking at your business
model level and possible at the form level, depending
on how you are doing forms.  Since I've been writing
my most recent business logic stuff with Moose, I've
been trying to use Moose's built in type checking for
a lot of that.  Still have a lot to learn with that.

For the top most layer of validation, associated with
a particular form,  I don't think this belongs in the
controller, I think it's more a view thing.  Lately
I've been doing it as macros in template toolkit, for
the most top level, final validation.  This is a
combination of Ajax style callbacks and client-side
Javascript.  Maybe that's ugly.  Not sure yet, I need
to work with a bit more.  Jquery has some nice plugins
to help with this.

--john

> 
> And should this branch of the thread be moved to the
> DBIC list?
> 
> Jason
> 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo:
> http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst mailing list