A little project ive been working on, please critique

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

A little project ive been working on, please critique

Post by bg »

This is a little project ive been working on for the last couple days. Maybe if it catches on I'll GPL it. Anyway, I'd like to have some people with experience critique the code and the way its done. Also feel free to contribute code or ideas.

I wanted to create some classes to handle html forms. A good portion of my coding goes into validating forms, getting data from them, setting their values from $_POST, etc. I figured why not create a class to handle all of that.

So far, this is what it does:

-Renders all form objects (XHTML)
-Crude handling of how form objects are displayed on page
-handles $_POST and will use those values if told to do so

What I'd like it to do in the future:

-Client side validation
-Server side validation

Some cool features are:
-Some inputs (right now, text and checkbox inputs) can be defined as multiple and will be created as input arrays.


And what currently needs to be improved/redone:
-layout handling, should use CSS instead of current method

Heres a brief description of how it works:

There are the input objects (input_text, input_select, input_textarea, input_checkbox, input_radio), the fieldset object, and finally the form object. The fieldset object contains a collection of inputs, and the form object contains a collection of fieldsets.

Most of the dirty work is done in the input objects. I used an abstract input class to keep the input objects as uniform as possible, but obviously each input required a lot of its own code because of how values are handled in the different inputs.

The fieldset object is very simple, its primary function is to serve as a nice way of organizing fields.

the form object is also pretty simple, but only because it doesn't implement a lot of the features I hope for it to eventually have.

Heres a zip of the files, make sure they're all in the same directory when you test.

Form Objects

BTW, this code requires PHP 5.

Thanks.

edit: index.php contains the test code. Viewing that first would be a good start.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I have had only a very brief look at your code so i'm not sure, but i think this: http://pear.php.net/package/HTML_QuickForm is the same as your project (but on steroids :))
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

timvw wrote:I have had only a very brief look at your code so i'm not sure, but i think this: http://pear.php.net/package/HTML_QuickForm is the same as your project (but on steroids :))
but its not written in php 5!! :D
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

thus it's more flexible than yours... :P
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

If it's written in PHP5 - doesn't make it perfect. How many hosts are actually running PHP5 to date? PHP4 is still the king until hosts migrate...
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

I would say a php4 script is more portable, not necessarily more flexible.
but i guess that depends on the definition of flexible
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

It meets both definitions until PHP5 is more widely adopted. If someone releases a PHP5 app tomorrow morning, just how flexible will it be when I go to upload it to my host? :)

j/k, php5 IS more flexible, but there's little advantage to using it's full potential until it's standard...
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

php5 IS more flexible, but there's little advantage to using it's full potential until it's standard...
the chicken and egg situation...
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

my host runs php 5, but then again, im the sys admin. :D
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Ignore the nay sayers - you will just be further ahead of the curve than they are.

BTW - I am working on a similar system in PHP5, nice to see my competitiion. :D
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

smpdawg wrote:Ignore the nay sayers - you will just be further ahead of the curve than they are.

BTW - I am working on a similar system in PHP5, nice to see my competitiion. :D
Cool, id be interested in seeing it :D
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

Maugrim_The_Reaper wrote: j/k, php5 IS more flexible, but there's little advantage to using it's full potential until it's standard...
Might be a problem for client side software, but not the case with PHP. If you were to start writing a php app right now, don't you think it would make more sense to write it in PHP5, since eventually it will be the standard?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

PRADO might be worth looking at for some ideas. I'm using it almost exlusively now :o
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

markl999 wrote:PRADO might be worth looking at for some ideas. I'm using it almost exlusively now :o
looks sweet. definatly looks like something id like to use
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

bgzee - I downloaded the zip and took a look at it. It looks good, clean and easy to read. I think you need to start over. :wink:

Seriously though, are you going to continue working on it or jump ship to Prado? I have to admit that I started looking at Prado a few months ago and it is impressive.

The reason I have stuck with my own framework is:

1. I started it over a year ago and I have a lot of time invested in it.
2. I have a different goal for my project.
Post Reply