[Newbie] Include Subform

I have searched and read the topics\tuts on forms and subforms, but they all seem to start in the middle, or the code is listed but doesn’t reference where it goes (model\controller??). In other words, it isn’t a complete tutorial.

Here’s where I am.

I have two models, Review and Reviewsub that were built with gii. I also have two forms, respectively. The review data is the main information like person, reviewdate etc… and the sub form contains multiple records for the indicated review like review elements and score.

I have the _form for the main Review working. I also have the _form for the review sub working. I need to know how to "include" the review sub form on the review form.

tl;dr I would very much appreciate a tutorial or short write up on how to include a subform inside another form.


No one? Can anyone post the steps for a parent child subform(view). I looked at partialrender() but cannot figure it out. The child form is from another model. I want to include the child form on the main form(view). I have built the relations. Any direction would be appreciated! thanks!

Hello Th3 R00ST3R, welcome to the forum.

I think it’s good to start with understanding the “tabular input”.

Collecting Tabular Input

And this wiki How to use single form to collect data for two or more models is also helpful.

A form with one model instance is very simple.

A form with 2 instances of 2 different models(the 2nd belongs to the 1st) is a little complicated but relatively easy. See the wiki above.

A form with multiple instances of a model (“tabular” input) is complicated. It’s a kind of “advanced” topic.

A form with (1) a instance of a model and (2) multiple instances of another model … (1) has many (2)s … this is what you want … is very much complicated, IMHO.

I think you may include the sub forms for the latter, but it should be a different one from the gii-generated form in order to handle the tabular inputs.

Have fun!

Thank you very much for the information and the kind welcome!

I think I have to rethink how I want the forms to behave. Tabular input may be the way to go.

I have the main form that has employee information and a drop down field that will filter the 2nd form (there are 5 options on the drop down I need to filter the 2nd form on).

Would it be better to have tabular input for each drop down option filter, or is there another way I should be thinking about this.

For context, it’s an employee evaluation form. The main form will have the employee information and a standards dropdown thay are rated on. There are 6 standards, each with their own elements. I need to be able to pick a standard that will show the elements related to that particular standard, then they can go to the next standard that will show it’s particular elements for ratings.

Is there an easier way to do what I want? Am I going about this the wrong way?

Any direction will be helpful. I will read up on the links you gave me. thanks!


Reviewing the "How to use single form to collect data for two or more models",

I created a new Controller called "Evaluation" and referenced the perfreview and perfreviewsub models. With the create.php, I created a new view folder called evaluation and made a new "create.php" file. Is that correct?

The issue I have with following the the tutorials is it doesn’t say whoch Controller and create.php. Do I need to modify an existing Controller and view, or should I have created new ones?

OK using this multimodelform extension i was able to get the parent, and child records to show in the update.php. I will have to play around with the extension to see if it’s what i want. So far it looks like I just need to do some formatting.

The other issue is with create.php. Since the child records don’t exist when creating the parent records, I get an error on the findall().

Thanks for the info.

Just an update. Try this: