Multi step forms


#1

sorry for re-posting this, my first one didnt seem to get through.

Is there an elegant way to handle forms in a controller/view that
need to go thru multiple steps. Like 1) validating content, and 2)
adding a step like first accepting an Agreement?

Just wondering if rails had a way to handle this without me having
to post to the controller twice and render a view based on a hidden
form value (input type=hidden name=step value=2 kind of thing)

thanks
adam


#2

On Friday 18 November 2005 01:08, Adam D. wrote:

sorry for re-posting this, my first one didnt seem to get through.

Is there an elegant way to handle forms in a controller/view that
need to go thru multiple steps. Like 1) validating content, and 2)
adding a step like first accepting an Agreement?

Just wondering if rails had a way to handle this without me having
to post to the controller twice and render a view based on a hidden
form value (input type=hidden name=step value=2 kind of thing)
No, AFAIK Rails doesn’t handle it for you. You need to develop your
own solution for the problem.

My guess would be to create an inermediate object, something like
ModelConstructor that will encapsulate models you’re creating from
the forms and handle their validations.

Then you can store this object in session, without saving it to the DB
until the final step is over. You can handle validation in middle
steps by calling Rails validate method inside Constructor object and
by stripping off all not-yet-filled fields from errors hash, to check
if model is correct for the current step.

Hope that helps.