multiple form in one view

Is there a complete example/solution for the following requirement in yii?

1.Collect data from user in one page but in different form for the same model.

eg. I have a table abc with the following columns


and need view for it like

First form

column1(Field is required.)



Second form(need last inserted id of first form)




2.Collect data for other model but in same above view

third form




thanks in advance

AS long as it is an update model and not create, yes you can do as the usual. Three forms that points to the same action, all you need is the model id to pass to the url.

As for creating model, this thing would be exactly as you had a 3 pages form. You would need to store data in session before validating and saving the whole stuff at the end.

The solution of yiimann seems to forget the point where you need the id of a the last inserted model.

Using Ajax validation call, you can control when the first part of the form is filled,

with a button or also on a simple loosefocus event.

On validation, create the model it represents and save it.

Update your form with the id received from the save.

As yiimann said, you need to store data in session.

So update the session to remember which record are still ‘pending’, or you can also mark your models directly in database as ‘pending’ in case the process gets simply aborted, you will trace back more easily the lost records.

Activate the 2nd part of the form, rinse and repeat validation/save/update session or db for all sections.

If you wish to cancel, remove added records from database as you still have their ids in the form.

If the process gets canceled without form submission, then having the model marked as ‘pending’ will be useful to clean database.