473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

At what point should I implement validation?

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:

register.php
classes/class.Form.php
classes/class.Validation.php
classes/class.User.php
classes/class.MySQL.php
templates/register.tpl.php

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.

Cheers

Phil
Jun 22 '07 #1
3 1774
On 22.06.2007 07:17 Phil Latio wrote:
[skip]
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.
ISBN 0201633612
ISBN 0321127420

hope this helps ;)
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Jun 22 '07 #2
Phil Latio wrote:
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:

register.php
classes/class.Form.php
classes/class.Validation.php
classes/class.User.php
classes/class.MySQL.php
templates/register.tpl.php

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.

Cheers

Phil

Phil,

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
class.

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.
js*******@attglobal.net
==================
Jun 22 '07 #3
Phil,
>
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
class.

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! :-)
Jerry

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.

Cheers

Phil
Jun 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Piotre Ugrumov | last post by:
How can I implement a function that calculate the coordinates of a point, in 3 dimensional space? The function take 6 value (x, y, z, v(velocity), corner alfa, corner beta). The prototype is...
8
by: Djanvk | last post by:
Ok I'm working on a program where you have say x number of seconds to do something. I'm at a loss on how to go about running a timer function. Can anyone point me in the right direction or post a...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
0
by: Martin | last post by:
Hi, I wanted to preform my own custom validation for the entire page so i though I would implemet the IValidator interface and do all of my validation in the "Validate" method, and this works...
4
by: Jarod_24 | last post by:
What is the point with Delegates in VB.Net What can these things do that we can not allready do with the use of Interfaces, Events and Event handlers and so on... I'd like a discussion on this,...
22
by: Nemisis | last post by:
Hi everyone, i am creating my own DAL and BLL, and i am not using typed datasets. My problem is that in my DAL i have a Save method whos signiture looks something like: Save(ID as integer,...
3
by: hello2008 | last post by:
Hi, I donot have much knowledge of R.Exp. In my web page I am required to validate numeric textboxes allowing signed/unsigned integer/float numbers and then compare between them. I need the...
4
by: dkyadav80 | last post by:
hi sir, I have following code: {code} <html> <body> Name:<input type="text" name="n1" id="n1"> DOB: <select name="dd"><option value="date">date</option>
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.