yiisoft/form 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yiisoft/form

最新稳定版本:1.5.1

Composer 安装命令:

composer require yiisoft/form

包简介

The package helps with implementing data entry forms.

关键字:

README 文档

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

Open Collective

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.

统计信息

  • 总下载量: 89.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 47
  • 点击次数: 1
  • 依赖项目数: 12
  • 推荐数: 0

GitHub 信息

  • Stars: 47
  • Watchers: 15
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-05-22