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

Comparing #3 with #4

Revision #4 was created by qiang qiang on Mar 11, 2009, 8:15:41 PM.

Reverted back to #1. Mentioning _form.php distracts the attention to the problem.

Content

[...]
...input fields for $a, $b...

</form>
```

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

 
 
 
 
Now, since version 1.0.3 and the `_form.php` view things change a litle. Folowing the example, we need to redlclare en the `create` view the parameters passed to the `create` view so the `_form` view can use them.
 
 
```php 
<h2>Create view</h2>
 
 
<div class="actionBar">
 
[<?php echo CHtml::link('List',array('list')); ?>]
 
[<?php echo CHtml::link('Manage',array('admin')); ?>]
 
</div>
 
 
<?php echo $this->renderPartial('_form', array(
 
'a'=>$a,'b'=>$b,
 
'update'=>false,
 
)); ?>
 
```
 
 
And in the `_form` work as ever (i.e. we can use $a and $b)