hustlahusky/forms
最新稳定版本:1.1.3
Composer 安装命令:
composer require hustlahusky/forms
包简介
README 文档
README
hustlahusky/forms
GitHub • Packagist • Installation • Usage
Installation
Via Composer
$ composer require hustlahusky/forms
Usage
use Hustlahusky\Forms\Builder\FormControlBuilder; use Hustlahusky\Forms\Handler\FormHandler; use Hustlahusky\Forms\Form; use Hustlahusky\Forms\FormControlSize; use Hustlahusky\Forms\Render; $form = new Form(); $form->addControl( FormControlBuilder::text('first_name', 'First Name') ->setRequired() ->setSize(FormControlSize::new(6)) ->build() ); $form->addControl( FormControlBuilder::text('last_name', 'Last Name') ->setRequired() ->setSize(FormControlSize::new(6)) ->build() ); $form->addControl( FormControlBuilder::email('email', 'Email') ->setRequired() ->setSize(FormControlSize::new(6)) ->build() ); $form->addControl( FormControlBuilder::phone('phone', 'Phone') ->setSize(FormControlSize::new(6)) ->build() ); $form->addControl( FormControlBuilder::radio('radio', 'Radio Buttons') ->setReadonly() ->addOption('1') ->addOption('2') ->addOption('3') ->setValue('1') ->build() ); $form->addControl( FormControlBuilder::select('select') ->setReadonly() ->addOption('1') ->addOption('2') ->addOption('3') ->setValue('1') ->build() ); $form->addControl( FormControlBuilder::select('select_multi') ->setReadonly() ->setMultiple() ->addOption('1') ->addOption('2') ->addOption('3') ->setValue(['1', '2']) ->build() ); $form->addControl( FormControlBuilder::checkbox('checkbox') ->setReadonly() ->setValue(true) ->build() ); $form->addControl( FormControlBuilder::checkboxMulti('checkbox_multi') ->setReadonly() ->addOption('1') ->addOption('2') ->addOption('3') ->setValue(['1', '2']) ->build() ); $render = new Render\BootstrapFormRenderer($form, [ Render\BootstrapFormRenderer::FORM_ATTRS => [ 'class' => 'w-100', ], Render\BootstrapFormRenderer::FIELDSET_ATTRS => [ 'class' => 'my-3', ], Render\BootstrapFormRenderer::LEGEND_ATTRS => [ 'class' => 'h3', ], Render\BootstrapFormRenderer::ROW_ATTRS => [ 'class' => 'my-2', ], ]); function output(iterable $iter): void { foreach ($iter as $item) { echo $item, \PHP_EOL; } } output($render->startForm()); output($render->renderControls()); output($render->submitButton()); output($render->endForm()); if ('post' === \strtolower($_SERVER['REQUEST_METHOD'])) { $handler = new FormHandler($form); $data = $handler->handle($_POST); }
Credits
License
The MIT License (MIT). Please see license file for more information.
统计信息
- 总下载量: 78
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-29