How to use a single form to collect data for two or more models?

Comparing #9 with #10

Revision #10 was created by JimJ JimJ on Jun 18, 2011, 6:08:47 PM.

Added more specific information for modifying a _form.php VIEW file.

Content

[...]
'b'=>$b,
));
}
```

And in the `create` view, we writeTo add these new fields to your Create form, add your 2nd table fields.  This is usually the _following code,rm.php file if you are working off Gii created CRUD files.
[...]
<?php echo CHtml::errorSummary(array($a,$b)); ?>

 <!-- ...input fields for $a, $b... -->
 
 
<div class="row">
 
<?php echo $form->labelEx($a,'a_field'); ?>
 
<?php echo $form->textField($a,'a_field'); ?>
 
<?php echo $form->error($a,'a_field'); ?>
 
</div>
 
 
<div class="row">
 
<?php echo $form->labelEx($b,'b_field'); ?>
 
<?php echo $form->textField($b,'b_field'); ?>
 
<?php echo $form->error($b,'b_field'); ?>
 
</div>
 


<?php echo CHtml::endForm(); ?>
```

The above approach can also be used if we have more than two models to deal with.
[...]