Multipart forms

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

Post Reply
Cole22
Forum Newbie
Posts: 7
Joined: Wed Apr 19, 2006 5:58 am

Multipart forms

Post by Cole22 »

Hi,

Here's a question to those who take the OO approach in PHP5.

I'm trying to implement a form with multiple parts.

The user fills in one part then clicks 'next'.
The user fills in the next part then clicks 'next' and so on until they reach the last part.
When they have filled that in, they click submit and the data is used to retrieve data from the database or used as input to the database.

How would you recommend applying the MVC pattern to this application or is this the wrong approach?

An initial idea is to have one view class for the whole form (every step). When one part is posted, the part is posted and the controller uses this value to work out which part to show next (after checking that the previous parts were filled in properly). What are everyone's thoughts on this?

Thanks for any feedback.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I just answered a question like this here --> viewtopic.php?p=296817#296817. Of course, that is procedural style, but I am sure you can adapt that to whatever style you want to code in. For me, simple is best. But if you want to throw some PHP5 OOP at it, code away.

Just make sure you post your code here so we can all gank it.:wink:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

The pattern for this is called the Application Controller. It is what is used for wizard type page sequences. It is the hardest controller to write because it is usually a state machine of some sort internally. At its simplest you can just store the pages that have been completed in the sequence in the session. You then have logic/rules that use that information to control access to what the user can view -- in addition to the logic/rules for each form.
(#10850)
Cole22
Forum Newbie
Posts: 7
Joined: Wed Apr 19, 2006 5:58 am

Post by Cole22 »

Thanks for the replies, yes, I was thinking that it should be a state machine of some kind.

Everah, I actually find that doing it the procedural way much more complex and difficult to unit test hence my question but everyone has their preference. :)
wei
Forum Contributor
Posts: 140
Joined: Wed Jul 12, 2006 12:18 am

Post by wei »

Post Reply