Application design in PHP - multiple step processes
When you're putting together a multiple step process in PHP (and that could be anything from a forum to an ordering system), you should bare in mind that each of the program elements will be the '
Application design in PHP - multiple step processes
When you're putting together a multiple step process in PHP (and that could be anything from a forum to an ordering system), you should bare in mind that each of the program elements will be the 'intermediate' step that takes you from one display to the next... and that you can't be sure when page "X" has been completed that the next page to be presented really WILL be page "Y" - after all, if the user has failed to enter his password correctly on page "X" you'll want to redisplay it...
... so here, in principle, is how your code should look. Your application will pick up form data and any existing information from the user's session, then "finish" processing from those inputs. Part of that finishing process will be making the decision as to what page to move onto next, so after finishing from page "X" the code will prepare for page "Y", or page "X" again perhaps. Upon completion of those preparations, the (newly updated) session is saved away, and a template for the new page completed.
Rather than store all the code associated with such a multipage application in one file / logical area, we'll usually split it up. The top level code goes into one file, the "business logic" - code to do the actual application work - into another. A third file contains the "web helpers" - routines which handle the forms, sticky fields, web principles, etc. And a fourth file contains a template - what the web page presented will actually look like.
By splitting the code in this way, it becomes easier to maintain as it's in sensible sized chunks. It also allows for elements to be reused in other areas of the web site / application - for example, a template might be shared right across a site, web helpers across many sites, and the business logic may be used offline as well as on the web. Finally, the division principle allows each section to be independently looked after by experts in that section - you need staff who are masters at each individual trade rather than staff who can dabble a bit in all areas.
If you have heard about MVC ("Model View Controller") parts of what I have written may sound very familiar indeed... and that is no accident!
We have a sample'shell' of an application that goes through a multistep process using these principle and you can run it here
. Source code is here (top level)
, here (business logic)
, here (web helpers)
and here (template)
This subject is taught briefly on our learning to program in PHP
and PHP programming
courses, and much more fully covered during our PHP techniques workshop (written 2009-05-11)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesH302 - PHP - MVC, 4 layer model and templating 
PHP training - refreshed modern course, backed up by years of practical experience - (2014-11-16) 
Teaching CodeIgniter - MVC and PHP - (2013-06-12) 
MVC and Frameworks - a lesson from first principles in PHP - (2013-04-19) 
Zend / layout of MVC and other files in an example application (PHP) - (2012-12-16) 
Separating program and artwork in PHP - easier maintainance, and better for the user - (2011-12-05) 
Your PHP website - how to factor and refactor to reduce growing pains - (2011-09-24) 
Adding a newsfeed for your users to a multipage PHP application - (2009-06-06) 
Improving the structure of your early PHP programs - (2009-05-25) 
Diagrams to show you how - Tomcat, Java, PHP - (2008-08-22) 
Larger applications in PHP - (2008-07-22) 
Kiss and Book - (2008-05-07)
Some other Articles
Melksham Candidates for Wiltshire Unitary ElectionPreventing forum spam - checks at sign upBalloon Journey in WiltshireMelksham in picturesApplication design in PHP - multiple step processesBasic OO principlesPHP4 v PHP5 - Object Model DifferenceCleaning up redundant objectsDesigning a heirarcy of classes - gett