Revision #10 has been created by JimJ on Jun 18, 2011, 6:08:47 PM with the memo:
Added more specific information for modifying a _form.php VIEW file.
« previous (#9) next (#11) »
Changes
Title
unchanged
How to use a single form to collect data for two or more models?
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
model validation
Content
changed
[...]
'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
_fo
llowing 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.[...]