webup/laravel-form
Composer 安装命令:
composer require webup/laravel-form
包简介
A Laravel package to help build forms.
README 文档
README
Install
Step 1: Install via Composer
$ composer require webup/laravel-form
Step 2: Add the Service Provider
Add this line to config/app.php:
'providers' => [ //... Webup\LaravelForm\FormServiceProvider::class ]
Step 3: Use Facade (optional)
For shorter code, you can use the facade by adding this line to config/app.php:
'aliases' => [ //... 'Form' => Webup\LaravelForm\Facades\Form::class, ]
You can now use Laravel Form directly into your views (check some examples bellow)
Step 4: Publish config
You can publish config and override it in config/form.php:
php artisan vendor:publish
Using
Methods
These methods can be used with any type of elements:
- label($label = null, $escape = true)
- value($value = null)
- placeholder($placeholder = null)
- name($name = null)
- required($showStar = true)
- errors($errors = [])
- attr(array $attr = [])
- wrapperAttr(array $attr = [])
- wrapperClass($wrapperClass) deprecated use wrapperAttr(['class' => 'myclass'])
Generated HTML
{!! Form::create('text', 'name')
->label('Name')
->value('Barney')
->required()
->attr(['maxlenght' => '50'])
->wrapperAttr(['class' => 'f-custom-class']) !!}
Without errors:
<div class="f-group f-custom-class"> <label for="name">Name <i class="f-required">*</i></label> <input type="text" id="name" name="name" value="Barney" maxlength="50"> </div>
With errors (retrieve from Laravel validation):
<div class="f-group f-custom-class f-error"> <label for="name">Name <i class="f-required">*</i></label> <input type="text" id="name" name="name" value="Barney" maxlength="50"> <ul class="f-error-message"> <li>Name is required</li> </ul> </div>
You can override default CSS class in config/form.php.
Important: Laravel Form can handle HTML generation and client side validation only. You need to manage server side validation on your own.
Elements
input
{!! Form::create('email', 'name')
->label('Email')
->value('homer.simpson@example.com')
->placeholder('example@adresse.com')
->required()
->wrapperAttr(['class' => 'custom-class']) !!}
textarea
{!! Form::create('textarea', 'name')
->label('Name')
->value('Nullam id dolor id nibh ultricies vehicula ut id elit.') !!}
radio
{!! Form::create('radio', 'gender')->label('Gender')
->addRadio(1, 'Male', 'male')
->addRadio(0, 'Female', 'female')
->wrapperAttr(['class' => 'custom-class'])
->value(0) !!}
Specific methods :
- addRadio($value, $label, $id, $attr = [])
select
{!! Form::create('select', 'fruits')
->label("Fruits")
->placeholder("What's your favorite?")
->addOptions(['apple' => 'Apple', 'strawberry' => 'Strawberry', 'melon' => 'Melon'])
->value('apple') !!}
Specific methods :
- addOptions(array $options)
checkbox
{!! Form::create('checkbox', 'cgu')
->label("I accept the general terms and conditions")
->value(true) !!}
You can use ->attr(['value' => '1']) to change the value of the checkbox
AntiSpam feature
Honeypot
{!! Form::honeypot("unicorn_mail") !!}
Will create an input text with name='unicorn_mail' within a hidden div (by javascript)
Validation
$request->validate([ [...] 'unicorn_mail' => 'honeypot', ]);
TimeTrap
{!! Form::timetrap("unicorn_time") !!}
Will create an input text with name='unicorn_time' and value="{encryptedTimestamp}" within a hidden div (by javascript)
Validation
$request->validate([ [...] 'unicorn_time' => 'timetrap:2', ]);
In this example, timetrap time is set to 2 seconds. If no value is set, config form.antiSpam.minFormSubmitTime is taken. Finally if config form.antiSpam.minFormSubmitTime is not set, default value is 3 seconds.
Styling
Bellow, you will find default styles that can work with Laravel Form.
.f-group { margin-bottom: 1rem; } .f-group label { margin-bottom: .5rem; } .f-required { color: #c0392b; font-weight: bold; } .f-error input { border: 1px solid #c0392b; } .f-error-message { margin-top: 4px; color: #c0392b; }
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Credits
Developed by Agence Webup
License
The MIT License (MIT). Please see License File for more information.
webup/laravel-form 适用场景与选型建议
webup/laravel-form 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.47k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2016 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「form」 「laravel」 「webup」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webup/laravel-form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webup/laravel-form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webup/laravel-form 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A Laravel Filament Forms slug field.
A jQuery augmented PHP library for creating and validating HTML forms
Laravel Admin made with Helium UI
Laravel contact us form package to send email and save to database
Alfabank REST API integration
统计信息
- 总下载量: 7.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-11