yiisoft/form
The package helps with implementing data entry forms.
Maintainers
Requires
- php: 8.1 - 8.5
- yiisoft/friendly-exception: ^1.0
- yiisoft/html: ^3.13 || ^4.0
- yiisoft/widget: ^2.2
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.3
- friendsofphp/php-cs-fixer: ^3.92
- maglnet/composer-require-checker: ^4.7.1
- phpunit/phpunit: ^10.5.45
- rector/rector: ^2.0.10
- spatie/phpunit-watcher: ^1.24
- vimeo/psalm: ^5.26.1 || ^6.9.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-06-24 21:47:16 UTC
README
Yii Form
👁 Latest Stable Version
👁 Total Downloads
👁 Build status
👁 Code Coverage
👁 Mutation testing badge
👁 static analysis
👁 type-coverage
👁 psalm-level
The package provides a set of widgets to help with dynamic server-side generation of HTML forms. The following widgets are available out of the box:
- input fields:
Checkbox,CheckboxList,Color,Date,DateTimeLocal,Email,File,Hidden,Image,Number,Password,RadioList,Range,Select,Telephone,Text,Textarea,Time,Url; - buttons:
Button,ResetButton,SubmitButton; - group widgets:
ButtonGroup,Fieldset. - other:
ErrorSummary.
These themes are available out of the box:
- Bootstrap 5 Horizontal,
- Bootstrap 5 Vertical.
Requirements
- PHP 8.1 - 8.5.
Installation
The package could be installed with composer:
composer require yiisoft/form
General usage
Configure themes (optional):
use Yiisoft\Form\ThemeContainer; use Yiisoft\Form\ThemePath; ThemeContainer::initialize( config: [ 'vertical' => require ThemePath::BOOTSTRAP5_VERTICAL, 'horizontal' => require ThemePath::BOOTSTRAP5_HORIZONTAL, ], defaultConfig: 'vertical', );
... and use Field helper to create widgets:
use Yiisoft\Form\PureField\Field; echo Field::text('firstName', theme: 'horizontal')->label('First Name')->autofocus(); echo Field::text('lastName', theme: 'horizontal')->label('Last Name'); echo Field::color('favoriteColor')->label('Favorite Color')->value('#3498db'); echo Field::select('sex')->label('Sex')->optionsData(['m' => 'Male', 'f' => 'Female'])->prompt('—'); echo Field::number('age')->label('Age')->hint('Please enter your age.'); echo Field::submitButton('Submit')->buttonClass('primary');
The result of executing the code above will be:
<div class="mb-3 row"> <label class="col-sm-2 col-form-label">First Name</label> <div class="col-sm-10"> <input type="text" class="form-control" name="firstName" autofocus> </div> </div> <div class="mb-3 row"> <label class="col-sm-2 col-form-label">Last Name</label> <div class="col-sm-10"> <input type="text" class="form-control" name="lastName"> </div> </div> <div class="mb-3"> <label class="form-label">Favorite Color</label> <input type="color" class="form-control" name="favoriteColor" value="#3498db"> </div> <div class="mb-3"> <label class="form-label">Sex</label> <select class="form-select" name="sex"> <option value>—</option> <option value="m">Male</option> <option value="f">Female</option> </select> </div> <div class="mb-3"> <label class="form-label">Age</label> <input type="number" class="form-control" name="age"> <div class="form-text">Please enter your age.</div> </div> <div class="mb-3"> <button type="submit" class="primary">Submit</button> </div>
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
Support the project
Follow updates
👁 Official website
👁 Twitter
👁 Telegram
👁 Facebook
👁 Slack
License
The Yii Form is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
