At what point should I implement validation?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am designing a relatively simple CMS with the usual Item, Category and  
User scenario. My question here relates to how I implement the User  
registration on this application. Currently I have the following:


The thing that is really bugging me is how I perform the validation on what  
is entered on the register.php page?

My first version (which I actually coded) simply created a new instance of  
the Validation class on the register.php page then performed numerous if  
statements with an error increment counter and if that returns zero (once  
all the tests are completed) then proceed else redisplay registration.php  
page. Works OK but looks terribly ugly and I am convinced there are far  
better approaches.

My second idea is to use CRUD methods within the User class and have the  
User class call the validation directly.

My third idea was to somehow apply the validation rules to the form objects.  
I have seen that some frameworks use this method but my problem is that I am  
really bad at understanding other people's code.

I keep hearing the term "design patterns" and just wondering if reading a  
book or two on that subject might clear my head on how to progress forward.  
The problem is not that I cannot code this, it's the approach I should take  
and would value some opinions by the piers of the group.



Re: At what point should I implement validation?

On 22.06.2007 07:17 Phil Latio wrote:

Quoted text here. Click to load it

ISBN 0201633612
ISBN 0321127420

hope this helps ;)

gosha bine

extended php parser ~
blok ~

Re: At what point should I implement validation?

Phil Latio wrote:
Quoted text here. Click to load it


Class objects should validate themselves - they shouldn't have to rely  
on outside code.  So in your case I would suggest validating in the user  

Also, beware - your "validation" class is probably not an appropriate  
class.  Does it have its own members (which aren't members of other  
classes)?  Or is it just validating some other class?  If the former, it  
would be a valid class.  However, it's easy to fall into a trap of the  
latter.  In that case it should be a method, not an object.

It's easy to get confused, especially when you get something like  
"validate" (a verb) and "validation" (a noun).  One is a method, one is  
a classes.

And btw - "display" is even worse! :-)

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: At what point should I implement validation?

Quoted text here. Click to load it


Many thanks for your thoughts. You make some interesting points and I hadn't  
considered taking that approach of validating within the user class or the  
form class.



Site Timeline