Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

DevArticles:
Forming PHP With OOP
Jan 24, 2003 @ 13:20:08

So, you've been slaving away, making those forms on your site just perfect - but you know there has to be a "better way" to do it. There's got to be a way to take anything that the user can throw at you, and, based on a single class, expand into a highly usable, easy to configure form interface. Sound scary? Well, it's not - and this article from DevArticles (Making PHP Forms Object-Oriented) will show you how to create it.

Their FormProcessor class basically acts as a "base element" for you to build from, making other classes extend it to use its functionality. Then, each of the other classes (like TextInput and RadioButtons) has a constructor and a render() function that can be used to create the actual form element.

And, of course, what would an article like this be without an example script to please the masses, and make it easier for the reader to see the overall picture. It's a nice way to handle making forms, and I could see doing this for a few forms, but so much of form input is specialized that, unless you have a pretty generic form, this class might just take up more time than it gives back....

tagged:

Link:


Trending Topics: