Handling 2 forms in one controller

Hi,

a brief description of my situation: I have 2 models, Item and
SellerContactInfo. They have to be filled with data from the user, which
is done in a 2-step web form. I’m thinking heavily about the optimal way
to do this:

A) Create 2 actions inside the same controller, use the session to store
the Item object and persist both objects to the db after the 2nd form
has been completed,

or

B) Create both forms on one HTML page, switch between them by
showing/hiding DIVs. Problem in this case: if the user fills out the 2nd
form and then validation fails for the 1st form, he/she will be thrown
back at the first form which reduces usability in my opinion.

Anyone have a usable idea of how to optimally solve this situation?

thx,
Robert

C) Create one action. Use request.post? To see if they’re just arriving
or have posted the form. Then use another if statement based on the
submit button’s value to see which form part has been submitted. If it’s
the first part, you can do your validation, store information in the
session and display the second part of the form. If the second form has
been submitted, you can do that validation and store your data.

Would that work?

Jason

On 28 September 2006 17:31, Robert S. wrote:

B) Create both forms on one HTML page, switch between them by
showing/hiding DIVs. Problem in this case: if the user fills out the 2nd
form and then validation fails for the 1st form, he/she will be thrown
back at the first form which reduces usability in my opinion.
I wouldn’t go with showing/hiding DIVs… It’s too problematic for me.

You can just make 3 actions (2 actions - for two forms and one to store
data
in DB and redirect), submit first form to second action, and second form

  • to
    third. When validation of first form in second action fails, just
    display
    first template (the same with second form). All submitted data could be
    stored in hidden fields so you don’t need to mess up with sessions.

I’ll try, thanks for sharing the idea :slight_smile: