Creating a form wizard - best practices?

I have been asked by a client to create a form that would automatically create an employee manual geared to a specific job site.

If the supervisor checked on the box that states the square footage is over 5,000 feet, the form would show cleaning instructions for that size of venue. If they checked unfinished construction, it would include rules regarding site cleanup. If there was no power on the site, it would include instructions on using a generator - and so on.

As you get further into the form, besides the simple A/B/C choices, it would also use information previously entered, to affect the new modules. For example, if will the walls of the site are to be primed, the instructions for the painting would take into account that the site has 5000 sq.ft. and that it is new unfinished construction.

Not too complicated, until we go through about 50 questions, and the instructions to be offered for each may need to be influenced by any or many of the questions before it.

I have been trying to work out a logic, and a database schema, that will handle this kind of recursive input.

I am certainly not asking anyone to provide the code to do this, I am just looking for some guidance on the best practices for this situation.

Is there some open source program, for any purpose, that uses a similar logic, so I could review their code?

Any help or guidance would be appreciated. I am working with PHP and mysql.
Who is Participating?
Ray PaseurConnect With a Mentor Commented:

I agree about CodeIgniter.  Zend Framework is very good, too.  

Some of my friends like Ruby on Rails for rapid prototyping (everything is an object in Ruby).

My only objection to the CMS or framework strategy is performance-based.  Some of them seem to take a long time to build a page.  But when you trade that off against the speed of app dev, it is often worth it.
I'd probably be building the SQL query on-the-fly using the checkboxes clicked on as additional WHERE clauses.

If you use AJAX then you can feed back to the user instantly how their options have altered the results/instructions.

At database level you can even include whether the additional clauses are AND or OR additions.

Ray PaseurCommented:
My preference for the design of something like this would be to use as few complex interactions as possible, making each piece of the puzzle as atomic as possible.  You would want to identify any dependencies (for example, to know how much paint to bring to the site, you would need to know the square footage of the surfaces to be painted, the number of coats, etc.) and order the questions so that all the antecedent data is gathered at the top of the form.

This is where object-oriented design can be very useful.

Example: Once you know you have to prime the walls, you can have a class devoted to prime painting that extends the main class.  The priming class can use data gathered above in the form, including such things as the square footage and the number of coats, to provide estimates about how much paint is required, etc.  

I like sushiguru's suggestion to use AJAX - you also could do the same thing with multiple form scripts, building out the data base record as each form is submitted.

There might be some inspiration in the PERT technique, too.

HTH, ~Ray
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

birwinAuthor Commented:
Thank you sushiguru and Ray_Paseur:
I like the idea of using AJAX to update the database as the questions are entered.
Ray, can you point me to a good tutorial on OO with PHP.?
Ray PaseurCommented:
Hi, Brian.  There are lots of OOP tutorials on the web.  Almost all of them try to give you simple examples of how OOP works, and that is fine, but the way OOP really has value cannot be seen until you begin to build layers of complexity.  You may look at the examples and say, "Why so much OOP stuff and so little functionality?"  But as functionality grows, the relative amount of OOP stuff declines and the organizational value of the OOP approach begins to shine.   So with that caveat, here are a couple of places to look:

On itself

These two articles by my fellow DCPHP colleague Jonathan Hilgeman:

And almost any of the books that are shown on this page (some deal with AJAX and PHP):

Best regards, ~Ray
sushiguruConnect With a Mentor Commented:
As an aside, I've recently moved to using codeigniter as a development framework and have found its organisation invaluable, and it becomes quite rapid to develop complex apps.  Worth a look. (and has a fab user guide and lots of resources/tutorials etc).

birwinAuthor Commented:
Thank you for your help and guidance
All Courses

From novice to tech pro — start learning today.