galahad/bootforms
Composer 安装命令:
composer require galahad/bootforms
包简介
Form builder with Bootstrap-specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.
README 文档
README
BootForms
BootForms is a Laravel package to rapidly generate markup for standard Bootstrap 3 forms. Probably not perfect for your super custom branded ready-for-release apps, but a huge time saver when you are still in the prototyping stage!
Check out Aire
This package has been replaced by Aire which is a modern form builder with similar features but an improved API, more tests, more documentation, and support for non-Bootstrap themes. It uses Tailwind by default, but has full support for Bootstrap via a plugin.
BootForms is no longer actively maintained. I'll try to merge any bugfixes for the forseeable future, but I strongly urge you to check out Aire.
Fork
This package forks abandoned Adam Wathan's repository to provide support for newer Laravel versions as well as following changes over the original package:
- support for package autodiscovery
- improved support for IDE autocompletion (using
laravel-ide-helper) - improved support for model binding
- changed into Laravel-only package to simplify experience even more
- dropped support for Laravel versions older than 5.5
Table of Contents
Installing with Composer
This package supports Laravel autodiscovery so all you have to do is running this command in your terminal in the root of your project:
composer require galahad/bootforms
Using BootForms
Basic Usage
BootForms lets you create a label and form control and wrap it all in a form group in one call.
// <form method="POST"> // <div class="form-group"> // <label for="field_name">Field Label</label> // <input type="text" class="form-control" id="field_name" name="field_name"> // </div> // </form> {!! BootForm::open() !!} {!! BootForm::text('Field Label', 'field_name') !!} {!! BootForm::close() !!}
Note: Don't forget to
open()forms before trying to create fields! BootForms needs to know if you opened a vertical or horizontal form before it can render a field, so you'll get an error if you forget.
Customizing Elements
If you need to customize your form elements in any way (such as adding a default value or placeholder to a text element), simply chain the calls you need to make and they will fall through to the underlying form element.
Attributes can be added either via the attribute method, or by simply using the attribute name as the method name.
// <div class="form-group"> // <label for="first_name">First Name</label> // <input type="text" class="form-control" id="first_name" name="first_name" placeholder="John Doe"> // </div> BootForm::text('First Name', 'first_name')->placeholder('John Doe'); // <div class="form-group"> // <label for="color">Color</label> // <select class="form-control" id="color" name="color"> // <option value="red">Red</option> // <option value="green" selected>Green</option> // </select> // </div> BootForm::select('Color', 'color')->options(['red' => 'Red', 'green' => 'Green'])->select('green'); // <form method="GET" action="/users"> BootForm::open()->get()->action('/users'); // <div class="form-group"> // <label for="first_name">First Name</label> // <input type="text" class="form-control" id="first_name" name="first_name" value="John Doe"> // </div> BootForm::text('First Name', 'first_name')->defaultValue('John Doe');
For more information about what's possible, check out the documentation for the basic Forms package.
Reduced Boilerplate
Typical Bootstrap form boilerplate might look something like this:
<form> <div class="form-group"> <label for="first_name">First Name</label> <input type="text" class="form-control" name="first_name" id="first_name"> </div> <div class="form-group"> <label for="last_name">Last Name</label> <input type="text" class="form-control" name="last_name" id="last_name"> </div> <div class="form-group"> <label for="date_of_birth">Date of Birth</label> <input type="date" class="form-control" name="date_of_birth" id="date_of_birth"> </div> <div class="form-group"> <label for="email">Email address</label> <input type="email" class="form-control" name="email" id="email"> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" class="form-control" name="password" id="password"> </div> <button type="submit" class="btn btn-default">Submit</button> </form>
BootForms makes a few decisions for you and allows you to pare it down a bit more:
{!! BootForm::open() !!}
{!! BootForm::text('First Name', 'first_name') !!}
{!! BootForm::text('Last Name', 'last_name') !!}
{!! BootForm::date('Date of Birth', 'date_of_birth') !!}
{!! BootForm::email('Email', 'email') !!}
{!! BootForm::password('Password', 'password') !!}
{!! BootForm::submit('Submit') !!}
{!! BootForm::close() !!}
Automatic Validation State
Another nice thing about BootForms is that it will automatically add error states and error messages to your controls if it sees an error for that control in the error store.
Essentially, this takes code that would normally look like this:
<div class="form-group {!! $errors->has('first_name') ? 'has-error' : '' !!}">
<label for="first_name">First Name</label>
<input type="text" class="form-control" id="first_name">
{!! $errors->first('first_name', '<p class="help-block">:message</p>') !!}
</div>
And reduces it to this:
{!! BootForm::text('First Name', 'first_name') !!}
...with the has-error class being added automatically if there is an error in the session.
Horizontal Forms
To use a horizontal form instead of the standard basic form, simply swap the BootForm::open() call with a call to openHorizontal($columnSizes) instead:
// Width in columns of the left and right side // for each breakpoint you'd like to specify. $columnSizes = [ 'sm' => [4, 8], 'lg' => [2, 10] ]; {!! BootForm::openHorizontal($columnSizes) !!} {!! BootForm::text('First Name', 'first_name') !!} {!! BootForm::text('Last Name', 'last_name') !!} {!! BootForm::text('Date of Birth', 'date_of_birth') !!} {!! BootForm::email('Email', 'email') !!} {!! BootForm::password('Password', 'password') !!} {!! BootForm::submit('Submit') !!} {!! BootForm::close() !!}
Additional Tips
Hiding Labels
You can hide labels by chaining the hideLabel() helper off of any element definition.
BootForm::text('First Name', 'first_name')->hideLabel()
The label will still be generated in the markup, but hidden using Bootstrap's .sr-only class, so you don't reduce the accessibility of your form.
Help Blocks
You can add a help block underneath a form element using the helpBlock() helper.
BootForm::text('Password', 'password')->helpBlock('A strong password should be long and hard to guess.')
Note: This help block will automatically be overridden by errors if there are validation errors.
Model Binding
BootForms makes it easy to bind an object to a form to provide default values. Read more about it here.
BootForm::open()->action( route('users.update', $user) )->put() BootForm::bind($user) BootForm::close()
galahad/bootforms 适用场景与选型建议
galahad/bootforms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62.6k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2017 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bootstrap」 「Forms」 「laravel」 「BootForm」 「bootforms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 galahad/bootforms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 galahad/bootforms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 galahad/bootforms 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
ConfirmationField is a form field for Atk14 applications. It's like the BooleanField (checkbox) but the ConfirmationField must be ticked.
Field for number with restricted count of digits and decimal places
HTML and form generation
Views for the package MedicOneSystems Livewire Datatables with Bootstrap 4
Build forms from schema
A Laravel Filament Forms slug field.
统计信息
- 总下载量: 62.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-21