Search by

yii2-extensions / dynamicform

Stefano Mtangoo

Yii2 widget for cloning nested form elements while maintaining accessibility and client validation.

Package info

github.com/yii2-extensions/dynamicform

Wiki

Language:JavaScript

Type:yii2-extension

pkg:composer/yii2-extensions/dynamicform

Statistics

Installs: 28 973

Dependents: 0

Suggesters: 0

Stars: 8

Open Issues: 0

2.0.0 2026-11-10 23:07 UTC

This package is auto-updated.

Last update: 2026-11-12 20:15:52 UTC


README

Yii Framework

Dynamic form


Testo Mutation Testing PHPStan Security

Clone nested form rows in Yii2 ActiveForm
Tabular inputs, client validation, nested widgets and jQuery events

Add and remove rows of form fields in the browser while the tabular input names, ids and client validation stay coherent. The widget wraps the rows rendered by ActiveForm, and the Model helper rebuilds the posted rows on the server.

Example application with nested property and room fields, live totals and custom styling

Quick start

Installation

composer require --prefer-dist yii2-extensions/dynamicform:^2.0

Basic usage

Wrap the rows of a tabular form with DynamicFormWidget::begin() and end():

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use Yii2\Extensions\DynamicForm\DynamicFormWidget;

$form = ActiveForm::begin(['id' => 'dynamic-form']);

DynamicFormWidget::begin(
    [
        'widgetContainer' => 'dynamicform_wrapper',
        'widgetBody' => '.container-items',
        'widgetItem' => '.item',
        'limit' => 4,
        'min' => 1,
        'insertButton' => '.add-item',
        'deleteButton' => '.remove-item',
        'model' => $modelsAddress[0],
        'formId' => 'dynamic-form',
        'formFields' => ['full_name', 'city'],
    ],
);
?>
<div class="container-items">
    <?php foreach ($modelsAddress as $i => $modelAddress): ?>
        <div class="item">
            <?= $form->field($modelAddress, "[{$i}]full_name")->textInput() ?>
            <?= $form->field($modelAddress, "[{$i}]city")->textInput() ?>
            <button type="button" class="add-item">+</button>
            <button type="button" class="remove-item">-</button>
        </div>
    <?php endforeach; ?>
</div>
<?php
DynamicFormWidget::end();

echo Html::submitButton('Save');

ActiveForm::end();

On the server, Model::createMultiple() builds one Address model per posted row; the usage examples show the complete create and update actions.

Documentation

AI assistance

AI agents: read the documentation index and fetch the Markdown version of a page by appending index.md to its URL. The AI agents guide covers skill installation, client setup and verification.

The hosted documentation covers Yii 22.0. If it does not match the installed revision or is unavailable, use the repository guides, the skill source, the source PHPDoc and the changelog.

Package information

PHP Yii 2.0.55+ Yii 22.0.x Latest Stable Version Total Downloads PHPStan Level Max

Code quality

Codecov Quality Assets ECS

Special thanks

This extension was created by Wanderson Bragança and hosted at wbraganca/yii2-dynamicform. We thank him for his work; for continuity and maintenance we have moved a copy here and preserve his identity throughout the code he wrote.

Our social networks

Follow on X Follow on Facebook Join our Subreddit Join on Telegram

Built with AI

Built with Claude Code Built with Codex Reviewed by CodeRabbit

License

License