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.Validatio n.php
classes/class.User.php
classes/class.MySQL.php
templates/register.tpl.ph p
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.ph p
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 3 1802
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
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.Validatio n.php
classes/class.User.php
classes/class.MySQL.php
templates/register.tpl.ph p
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.ph p
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*******@attgl obal.net
=============== ===
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 this:
double coordinate(double x, double y, double z, double c, double alfa,
double beta);
How can I implement a function that return the corner alfa e beta? The
funcion take the coordinates of 2 point.
|
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
snippet of code for me to look at?
The program I'm trying to write is a 2nd grade math program to help my
daughter with her addition and subtraction.
Thanks
|
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) show the error message next to
the control. For example, if the text field is empty with RequiredField
Validator control, it can show the value in ControlToValidate property in
two ways as I mentioned.
Please advise. Thanks!
|
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 well with one small problem.
The "Page" class has a property called "IsValid" which is read-only.
IValidator implements a private variable called isvalid
|
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, and some practical examples where Delegates would be better/worse to use...
| |
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, name as string, .......
|
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 textboxes to accept values only between -10 to +10. Please help? Below is my code
<html>
<head>
<title>
Display Requirements
</title>
|
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>
|
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 problems
later). Apparently Point is a struct, a value type, and it does not
behave like a classic structure (in my mind's eye, and see below).
Traditionally I think of a classic structure as simply an object where
every member is public. But with...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |