Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ilyes512's avatar

How to structure multistep form?

So I just started my second project where I need to use a "multistep" form. What I mean by that is something like this:

Page 1:
Fill in your email and password plus confirmation and press "Next" (submit).
Page 2:
Fill in your personal details like name etc. Press either "Next" (submit) or press "Previous" to go back to step 1 and change something there.
Page 3:
Fill in some other bio stuff for your profile and press either "Finnish" to complete or press "Previous" to go back one step.

So for a registration progress like above I would save everything in a session until the last step ("Finnish" button). But I also have cases where I want to write everything right away in a database (not for registration but for going trough something else).

So normally I always use resource controllers, but I am not sure what to use for these multistep forums. Should I add new method's to the resource and manually add those to the route? Or should I use a basic controller and create something like getStepOne, postStepOne, getStepTwo,...

A real example where I need to apply this multistep form is a newsletter system I am currently working on. A user would need to go trough a sort of wizard (multistep form) which ask's for all kind of information like subject, emails, group, article's to send etc. The user should be able to save at any one point so I need to store it after each step. This will lead to tables that are only partly filled until the wizard has been completed by the user.

So any idea's on how to handle this nicely? (Currently I am using a few patterns like Gateway Services, Validation Services, Repositories and Services Providers. Not sure if this might make any difference?).

0 likes
6 replies
hromby's avatar

I think I would handle much of it client-side. There is a Bootstrap Form Wizard plugin which I've actually recently used in a project, and it does a very good job.

It works by having the entire form on the page, but divided into tabs. It fires events on tab changes, so you could fire an Ajax request with the current data in the form when a user switches tab to save the progress.

ilyes512's avatar

@hromby
Thanks! That looks really promising. But I still wonder how I should manage/structure my controller. I want to keep things maintainable and testable.

Also I need the user to fill in the wizard in order. I probably can manage this by keeping track of the completed steps in JS (var last_step) and also check this with the last_step that I will store somewhere in the DB (or else a user can remove the disabled classes and/or alter the JS variable trough the console - or is there a better way of solving this?).

Valorin's avatar

I'd probably use a dedicated wizard controller, with custom actions for each step in the form.

It's not really a resource if it's got complex form logic, so would make sense to extract to it's own controller.

ilyes512's avatar

I am not quite happy with what I got now. I am going to try it again tomorrow.

niall_obrien's avatar

These days I'd probably handle the majority of this on the client (localStorage + fallbacks if needed) then when they reach the last step, submit the whole lot of it. Makes life easier if you're comfortable with JS tbh.

Please or to participate in this conversation.