Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- At what point should I implement validation?
- Phil Latio
June 22, 2007, 5:17 am
rate this thread
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
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?
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
And btw - "display" is even worse! :-)
Remove the "x" from my email address
JDS Computer Training Corp.