PHPackages                             prawee/yii2-dependform-widgets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. prawee/yii2-dependform-widgets

ActiveYii2-widget

prawee/yii2-dependform-widgets
==============================

How to using relations model in single form

00PHP

Since Jun 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/prawee/yii2-dependform-widgets)[ Packagist](https://packagist.org/packages/prawee/yii2-dependform-widgets)[ RSS](/packages/prawee-yii2-dependform-widgets/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

How to validate multiple model in single form
=============================================

[](#how-to-validate-multiple-model-in-single-form)

Example us case
---------------

[](#example-us-case)

Have 2 table need to save as the same time and depend on you pick amount of member of team

```
team
- id
- name
- member

person
- id
- team_id
- name
- position
- experience
```

Usage
-----

[](#usage)

### View

[](#view)

```
use prawee\widgets\DependWidget;
...
$form = ActiveForm::begin(['id' => 'depend-form']);
echo $form->field($team, 'name', ['options' => ['class' => 'col-md-8']])->textInput(['autofocus' => true]);
echo $form->field($team, 'member', ['options' =>['class' => 'col-md-4']])->dropDownList([
    1 => 1,
    2 => 2,
    3 => 3,
    5 => 5,
    8 => 8,
    10 => 10,
],['prompt' => 'select']);
echo DependWidget::widget([
    'form' => $form,
    'model' => $person,
    'attributes' => [
        'name',
        'position',
        'experience' => [
            'type' => 'select',
            'list' =>[1 => '1-2', 2 => '3-5', 3 => '5 >', 4 => '10 >']
        ],
    ],
    'attributeOptions' => ['class' => 'col-md-4'],
    'depends' => [Html::getInputId($team, 'member')]
]);
?>

     'btn btn-primary', 'name' => 'contact-button']) ?>

```

[![alt normal](https://github.com/prawee/yii2-dependform-widgets/raw/master/src/images/yii2-validate-muliple-model-1.png)](https://github.com/prawee/yii2-dependform-widgets/blob/master/src/images/yii2-validate-muliple-model-1.png)

[![alt action](https://github.com/prawee/yii2-dependform-widgets/raw/master/src/images/yii2-validate-muliple-model-2.png)](https://github.com/prawee/yii2-dependform-widgets/blob/master/src/images/yii2-validate-muliple-model-2.png)

### Controller

[](#controller)

```
...
public function actionCreate()
{
    $team = new Team();
    $person = new Person();

    $post = \Yii::$app->request->post();
    if (Model::loadMultiple([$person], $post) && Model::validateMultiple([$person])) {
        $team->load($post['Team']);
        foreach($post['Person'] as $person):
            $person->load($person);
            $person->team_id = $team->id;
            $person->save();
        endforeach;
        $team->save();
        return $this->redirect(['index']);
    }

    return $this->render('create', [
        'team' => $team,
        'person' => $person
    ]);
}
...
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3203937?v=4)[Prawee Wongsa](/maintainers/prawee)[@prawee](https://github.com/prawee)

### Embed Badge

![Health badge](/badges/prawee-yii2-dependform-widgets/health.svg)

```
[![Health](https://phpackages.com/badges/prawee-yii2-dependform-widgets/health.svg)](https://phpackages.com/packages/prawee-yii2-dependform-widgets)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
