megaurav2002 has asked for the wisdom of the Perl Monks concerning the following question:


Hello Monks,

i am working on a website using catalyst. Users are required to fill some forms which are 4-5 pages long. While filling the form he may opt to go to the previous page to edit details he has previously filled.if he goes back to the previous page I need to show him all his details he chose/filled on the previous page.
I am using session to store all his details he is filling in the form. When he goes back to the previous pages, i take the information from the session and i fill them in the pages.
Now the problem is that if users opens two forms together and fills some data and then goes back to previous page, the session shows him the data (he filled in the second form )in the first form.
I know the problem is that they are using same session. But how to avoid this? Any help will be highly appreciated!

Gaurav Talwar
"Wisdom begins in wonder" - Socrates, philosopher

Replies are listed 'Best First'.
Re: session problem
by NetWallah (Canon) on May 24, 2007 at 04:22 UTC
    How about if you generate a unique ID (perhaps an MD5 number with a combination of timestamp and a random number) for each instance of the form (i.e. each form request).

    Place this unique ID as a hidden field on the form - then you can distinguish between form instances - of course, you will need to save the unique ID in the session as well (since you use the session as temporary storage).

    Alternatively, you could store the unique ID and associated form values in a database, avoiding the need to trust client-side cookies.

         "An undefined problem has an infinite number of solutions." - Robert A. Humphrey         "If you're not part of the solution, you're part of the precipitate." - Henry J. Tillman

Re: session problem
by ph713 (Pilgrim) on May 24, 2007 at 07:04 UTC
Re: session problem
by mattr (Curate) on May 24, 2007 at 13:43 UTC
    Hi,

    I've been using formbulder (Catalyst::Controller::FormBuilder, based on CGI::FormBuilder) and like it. CGI::FormBuilder docs do mention multi-screen forms.

    But I've built a catalyst portal recently with lots of forms and never had a problem or needed multipage forms myself.

    The logged in user is found ($c->user) and is automatically managed via Catalyst's authentication and session capabilities. So I always show forms prepopulated from the db keyed to the user, and then save immediately.

    I don't use the session manually myself, though you could persist stash in $c->flash. I think maybe you are making things too complicated, maybe using the same form field names in different forms. That's bad!

    Try FormBuilder. You can make one definition for each form, or if you are dying to make multi-screen forms then make a big definition and then I guess you will want to change which fields are hidden depending on theform page number. Hope this helps.