hustlahusky / forms
1.1.3
2023-04-27 09:26 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- symfony/polyfill-php80: ^1.27
- symfony/property-access: ^5.0|^6.0
- yiisoft/html: ^2.0|^3.0
Suggests
- symfony/property-access: ^5.0|^6.0
- yiisoft/html: ^2.0|^3.0
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.