Page 1 of 1

Multipart forms

Posted: Mon Aug 14, 2006 4:21 am
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.

Posted: Mon Aug 14, 2006 4:31 am
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:

Posted: Mon Aug 14, 2006 4:37 am
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.

Posted: Mon Aug 14, 2006 8:27 am
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. :)

Posted: Mon Aug 14, 2006 6:58 pm
by wei