Save and new button along with create button


is it possible to create a "Save and new" button in an active form along with the classic "Create" button?

I have to give the users the possibility of choose if save and be redirected to the list of items or to save and insert another item.

I know that I can edit the controller changing the final render view from "index" to "create" but how to keep each possibility?

Thank you


The post mechanism uses a form with a target so you would need a single action. You could either add a checkbox ("create another") instead of a second button or otherwise use a hidden checkbox, set its value from the "save and create" button in Javascript and then submit the form from teh same javascript.

In the action, just check for the value of the checkbox in the post() data and redirect depending on what it is.

it’s called tabular input. there is an extension to do it in a grid view (Tabular Form WIdget). I don’t know if it will work in your case (gridview) if not then you can create your own.

for just a form

foreach in actionCreate to loop through each model instance and save into db.

do a foreach in actionUpdate to retrieve all models to update from db.

Yii2 Wiki Article

Another Extension

view page you will need js to copy form fields and duplicate the add item section

JS Plugin to copy form fields and demo

Then save would just save all of them and the "add more" button would just duplicate the fields for more input.

I don’t know if any of the article or plugins are good but they should defiantly lead you to the right answer.