yiisoft / form
The package helps with implementing data entry forms.
Fund package maintenance!
Open Collective
yiisoft
Installs: 67 638
Dependents: 11
Suggesters: 0
Security: 0
Stars: 44
Watchers: 18
Forks: 20
Open Issues: 3
Requires
- php: ^8.1
- yiisoft/friendly-exception: ^1.0
- yiisoft/html: ^3.7
- yiisoft/widget: ^2.2
Requires (Dev)
- infection/infection: ^0.26.19
- maglnet/composer-require-checker: ^4.7
- phpunit/phpunit: ^10.5
- rector/rector: ^1.2
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^5.21
This package is auto-updated.
Last update: 2024-10-09 13:18:40 UTC
README
Yii Form
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
,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 or higher.
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::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">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
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.