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

Matt S Trout dbix-class at trout.me.uk
Tue May 15 20:30:39 GMT 2007


On Tue, May 15, 2007 at 02:51:18PM -0400, Christopher H. Laco wrote:
> > where do you handle the validation? Only in the controller or in
> > both the model and controller?
> 
> Fail Early. Fail Often.
> 
> Some will say redundancy sucks. I agree, except for where validation is
> concerned. If you're writing data from the web into a model, check the
> data at the page level, and at the model level.
> 
> If you're writing to a model from a command line utility...check data at
> the command line level, and the model level...

The controller should validate.

The model should also validate.

The model should provide a way for the controller to get the constraints.

The controller should check the constraints and return errors to the user,
and if there are errors NOT TRY AND UPDATE THE MODEL.

The model's validation should die screaming if it doesn't pass - if bad data
gets that far, either the model's changed under you or there's a bug in
your code.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/             http://www.shadowcatsystems.co.uk/ 



More information about the Catalyst mailing list