Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Making forms object-oriented
Analysis
Let's take a look at the task of processing user forms and try to find the most common steps. They will describe generic functionality of a form. First of all, a form must be presented to user. This includes rendering graphical representation of form objects (which is carried out by browsers quite efficiently). Then we must display the initial values; this should be governed by application logic. Then the user's input must be received and analyzed. We receive a set of values from user. At the abstract level the decision that is made on this stage would usually be: can this form be considered completed or should we go back and ask user to correct something.
Let's first look at the situation when we need something corrected. In this case an application must display the form again and give some explanations about what went wrong (display some error messages). Besides, a well-mannered form should preserve values entered by user, at least the correct ones. Now suppose, we decide that the values are good enough to allow us to continue. Then these values (or some of them) usually get stored somehow (in a database, in session variables). Finally, another decision is made: where do we go from here? It is often based on values entered and, of course, follows some paths defined by programmer.
Now, what should we try to achieve by the object analysis? The best would be to program generic behavior in parent class(es) once and forever. Then from that moment on we will be able to only concentrate on context-specific steps for each new form that we develop: check values, store values, decide where to go from the form.
The key element will be a generic form class that I called FormProcessor. Let's first have a general idea about how it works. I like putting forms into separate files. There's nothing that makes it necessary, it just makes things easier, for example, to edit them in visual editors. Also, I usually have forms that 'submit to themselves', in other words I usually group a form with code that takes its input. One idea is to create instances of FormProcessor's sub-classes in the beginning of such files. Then, this instance will 'tune in' the environment and will be able to have complete control over displaying the form and working with it further on. By 'tuning in', I mean deciding whether this particular form was displayed and submitted before and we should now check the input. If it has never been submitted before, it should be displayed for the first time. Object-oriented technology will work for us in both situations. Generic framework within FormProcessor will run one of the virtual member functions -- either for checking or for displaying the form. Notice: all we will have to do in each particular form's class is override these virtual functions. In the same way, we will override the function responsible for storing form's values. Again, generic class will decide when to call it.
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
RE: TextArea using this oo formEugenio Costa08/09/04 22:51
RE: php developers don't recommend this approachKerry Kobashi04/13/03 19:50
wow, I'm impressed!SkunkAh01/03/03 07:01
Scary!Yoran|Nimation.nl12/26/02 18:00
RE: How do I pass an object to another php?Douglas Hammond11/29/02 15:23
OOH Forms getting to imagedigitalbart2k08/15/02 18:11
Thanks YuriSimo07/15/02 07:55
adminDoctor07/11/02 14:01
Where to start?James07/10/02 13:16
Can you do this with PHPL Sanders 06/14/02 14:57
TextArea using this oo formAlbino Matesic06/04/02 15:56
phpObjectForms V.1.0 Released at SourceForgeilya05/26/02 18:36
RE: php developers don't recommend this approachAndreas05/22/02 19:13
RE: php developers don't recommend this approachMarc Miles05/17/02 02:18
RE: Why stop at forms?Jason Marquand05/16/02 11:26
RE: The $HTTP_* vars will be gonedarrenashdoers05/16/02 02:55
object oriented approachkhalid mahmood04/19/02 11:51
Why stop at forms?James Gregory04/18/02 03:09
RE: Nice intention but poor codemindwarp04/04/02 04:08
RE: OO is the way to go.. And I can proove itPablo Liska03/25/02 15:07
bdfbgbgdfbdfbdbd03/25/02 05:18
The $HTTP_* vars will be goneHéctor03/20/02 07:56
RE: How do I pass an object to another php?Rod K03/07/02 09:07
How do I pass an object to another php?Alex03/05/02 23:40
php ?rakesh01/28/02 05:56
Information holding ....Khanh01/25/02 00:45
PHP - users updating pagesKen01/21/02 10:20
RE: is php not good enought for OOP?Bernd01/16/02 07:34
RE: php developers don't recommend this approJoe Stump01/13/02 23:25
RE: php developers don't recommend this approachlorenz kitzmann01/09/02 13:27
Thanks YuriJon Conley01/07/02 10:33
is php not good enought for OOP?farid01/05/02 10:36
RE: OOP - how big is too big?Tim12/20/01 18:26
OO is the way to go.. And I can proove itcopious12/10/01 10:00
The fat way: OOH Form RewriteUlf Wendel12/06/01 11:43
RE: not even close to goodSimon12/03/01 09:50
Web based Form generatorSimon12/03/01 08:34
RE: php developers don't recommend this approachTim Parkin11/30/01 07:14
RE: php developers don't recommend this approachron hatt11/28/01 10:48
RE: php developers don't recommend this approachBob11/25/01 20:59
RE: OOP - how big is too big?Prof11/20/01 07:42
OOP - how big is too big?g_M_e11/13/01 14:47
HelloMuhammad Arif11/13/01 00:46
RE: php developers don't recommend this approachmichael kristopeit11/12/01 16:22
RE: php developers don't recommend this approachPeter11/11/01 04:31
RE: php developers don't recommend this approachPeter11/11/01 04:29
RE: php developers don't recommend this approachsantosh11/09/01 03:52
RE: php developers don't recommend this appromorpheus()11/04/01 23:44
RE: Why not PEAR?Philip Olson11/03/01 15:19
RE: Resource UsageGerardo Tasistro11/03/01 15:03
RE: php developers don't recommend this approachMichael Kristopeit11/02/01 05:26
RE: php developers don't recommend this approachMichael Kristopeit11/02/01 04:24
RE: RE: Resource UsageVincent Oostindie10/30/01 18:27
RE: php developers don't recommend this approachmorpheus()10/29/01 09:05
RE: RE: Resource Usagemorpheus()10/29/01 08:57
Yuri: OOP not a bad ideaHoracio Lopez10/27/01 21:45
RE: Why not PEAR?Jeff10/26/01 12:20
RE: php developers don't recommend this approachJeff10/26/01 12:11
RE: not even close to goodRoy Walter10/25/01 15:07
RE: Nice intention but poor codeChristopher Brand10/25/01 12:01
RE: 6 out of 10tobias beuving10/23/01 11:33
Why not use PHPLIB ooforms and tpl_formAlejandro Miguel10/22/01 03:40
not even close to goodken egervari10/21/01 09:00
RE: 6 out of 10vincent10/19/01 03:46
Thank you!Henry10/18/01 19:58
Nice intention but poor codeAxel Napolitano10/18/01 16:10
RE: 6 out of 10Yuri Makassiouk10/18/01 14:23
RE: Resource UsageYuri Makassiouk10/18/01 14:10
RE: Why not PEAR?Tipper Gore10/18/01 13:20
RE: RE: Resource UsageTipper Gore10/18/01 13:16
RE: RE: Resource UsageVincent Oostindie10/18/01 04:36
RE: Why not PEAR?Vincent Oostindie10/18/01 04:32
php developers don't recommend this approachmichael kristopeit10/17/01 19:11
RE: Resource Usagemorpheus()10/17/01 00:29
QuestionFrancesco Tinti10/16/01 14:14
Resource UsageEric10/16/01 11:55
Why not PEAR?Tom Anderson10/16/01 11:17
6 out of 10vincent10/16/01 08:09
Ãåíèàëüíî! / Great!Dolce10/16/01 08:08
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.