Next, Finish Form

I am making a form which has a few different fields and a Next and
Finish button that walks the person through the form.

I have the fields hidden then make them appear as the person progresses
through the form. The fields after a certain step are optional so I
would like to make the finish button appear at that step too.

I am struggling on how to maintain state. Should this be held in the
session object, a cookie or what. Also I have not got figured out how
to make the “next” action smart enough to handle all these states.

Any input or examples would be great.

Dave Waller