PHPackages                             xaboy/laravel-form-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xaboy/laravel-form-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xaboy/laravel-form-builder
==========================

laravel专用表单生成器，快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。

1.2.1(7y ago)632668[5 issues](https://github.com/xaboy/laravel-form-builder/issues)MITPHPPHP &gt;=5.4.0

Since Aug 6Pushed 7y ago3 watchersCompare

[ Source](https://github.com/xaboy/laravel-form-builder)[ Packagist](https://packagist.org/packages/xaboy/laravel-form-builder)[ Docs](https://github.com/xaboy/laravel-form-builder)[ RSS](/packages/xaboy-laravel-form-builder/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (6)Used By (0)

laravel-form-builder
====================

[](#laravel-form-builder)

 [![MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667) [ ![xaboy](https://camo.githubusercontent.com/c5b4e9f11682a5b66b3dfeef8d97cead336edb7d69ed865a9107b9e6c61b41e9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417574686f722d7861626f792d626c75652e737667) ](https://github.com/xaboy) [ ![version](https://camo.githubusercontent.com/3d22e42fbb23767a3c1ddf733871422ea3030c27b958379cc62a153d6832d964/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7861626f792f6c61726176656c2d666f726d2d6275696c6465722e737667) ](https://packagist.org/packages/xaboy/laravel-form-builder) [ ![php version](https://camo.githubusercontent.com/2c6064477eb69e22bfb5b0d8fdfa7feef71e7304cace39fd7e2acb051526f153/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7861626f792f6c61726176656c2d666f726d2d6275696c6465722e737667) ](https://packagist.org/packages/xaboy/laravel-form-builder)

laravel专用表单生成器，快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及省市区三级联动、时间选择、日期选择、颜色选择、树型、文件/图片上传等功能。

#### 支持laravel 5.x

[](#支持laravel-5x)

#### 如果对您有帮助，您可以点右上角 "Star" 支持一下 谢谢！

[](#如果对您有帮助您可以点右上角-star-支持一下-谢谢)

#### 本项目还在不断开发完善中,如有建议或问题请[在这里提出](https://github.com/xaboy/laravel-form-builder/issues/new)

[](#本项目还在不断开发完善中如有建议或问题请在这里提出)

安装
--

[](#安装)

```
$ composer require xaboy/laravel-form-builder
```

配置
--

[](#配置)

1. 添加下面一行到 `config/app.php` 中 `providers` 部分：

    ```
    LaravelFormBuilder\FormBuilderProvider::class,
    ```
2. 发布配置文件与资源

    ```
    $ php artisan vendor:publish --provider='LaravelFormBuilder\FormBuilderProvider'
    ```
3. 模板引入依赖资源

    这行的作用是引入编辑器需要的 css,js 等文件，所以你不需要再手动去引入它们。

    如果项目中已包含`vue`、`iview`、`jquery`其中任意,可在`vendor/form-builder/assets.blade.php`文件中手动移除。

    **注意 iview版本为2.14.3,vue版本为2.5**

    ```
    @include('vendor.form-builder.assets')
    ```
4. 加载表单规则

    ```
    //@include('vendor.form-builder.script',['form'=>$form,'id'=>'store']);
    @include('vendor.form-builder.script',['form'=>$form]);
    ```
5. 表单初始化

    表单会自动添加`csrf_token`,无需手动设置

    ```

        //laravelFormCreate_store('.panel-body');
        laravelFormCreate('.panel-body',function callback(status, res, $f, formData){
         //表单提交回调函数
           if(!status)
               //TODO 表单提交成功
            else
               //TODO 表单提交失败
       });

    ```

说明
==

[](#说明)

1. 5.4+ 请不要忘记 `php artisan storage:link`
2. 如果你使用的是 laravel 5.3 以下版本，请先创建软链接： ```
    # 请在项目根目录执行以下命令
    $ ln -s `pwd`/storage/app/public `pwd`/public/storage
    ```

示例
--

[](#示例)

[![https://raw.githubusercontent.com/xaboy/laravel-form-builder/master/demo.jpg](https://raw.githubusercontent.com/xaboy/laravel-form-builder/master/demo.jpg)](https://raw.githubusercontent.com/xaboy/laravel-form-builder/master/demo.jpg)

代码
--

[](#代码)

```
namespace Test;
use LaravelFormBuilder\Form;

//input组件
$input = Form::input('goods_name','商品名称');

//日期区间选择组件
$dateRange = Form::dateRange(
    'limit_time',
    '区间日期',
    strtotime('- 10 day'),
    time()
);

//省市二级联动组件
$cityArea = Form::city('address','收货地址',[
    '陕西省','西安市'
]);

$checkbox = Form::checkbox('label','表单',[])->options([
    ['value'=>'1','label'=>'好用','disabled'=>true],
    ['value'=>'2','label'=>'方便','disabled'=>true]
])->col(Form::col(12));

$tree = Form::treeChecked('tree','权限',[])->data([
    Form::treeData(11,'leaf 1-1-1')->children([Form::treeData(13,'131313'),Form::treeData(14,'141414')]),
    Form::treeData(12,'leaf 1-1-2')
])->col(Form::col(12)->xs(12));

//创建form
$form = Form::create('/save.php',[
    $input,$dateRange,$cityArea,$checkbox,$tree
]);

$html = $form->formRow(Form::row(10))->setMethod('get')->setTitle('编辑商品')->view();

//输出form页面
echo $html;
```

AJAX请求返回类
---------

[](#ajax请求返回类)

`namespace \LaravelFormBuilder\Json`

- **Json::succ(msg,data = \[\])** 表单提交成功
- **Json::fail(errorMsg,data = \[\])** 表单提交失败
- **Json::uploadSucc(filePath,msg)** 文件/图片上传成功,上传成功后返回文件地址
- **Json::uploadFail(errorMsg)** 文件/图片上传失败

Form 表单生成类
----------

[](#form-表单生成类)

`namespace \LaravelFormBuilder\Form`

- **components(array $components = \[\])** 批量添加组件
- **formRow(Row $row)** 设置表单Row规则
- **formStyle(FormStyle $formStyle)** 设置表单样式
- **setAction($action)** 设置提交地址
- **getConfig($key='')** 设置配置文件
- **setMethod($method)** 设置提交方式
- **setMethod($method)** 设置提交方式
- **append(FormComponentDriver $component)** 追加组件
- **prepend(FormComponentDriver $component)** 开头插入组件
- **getRules()** 获得表单规则
- **view()** 获取表单视图
- **script()** 获取表单生成器所需全部js
- **formScript()** 获取生成表单的js代码,可用js变量接受生成函数`create`,执行`create(el,callback)`即可生成表单
- **getScript()** 获取表单生成器所需js
- **create($action, array $components = \[\])** 生成表单快捷方法
- **setTitle($title)** 设置title

FormStyle表单样式
-------------

[](#formstyle表单样式)

- **Form::style**

```
 * @method $this inline(Boolean $bool) 是否开启行内表单模式
 * @method $this labelPosition(String $labelPosition) 表单域标签的位置，可选值为 left、right、top
 * @method $this labelWidth(Number $labelWidth) 表单域标签的宽度，所有的 FormItem 都会继承 Form 组件的 label-width 的值
 * @method $this showMessage(Boolean $bool) 是否显示校验错误信息
 * @method $this autocomplete($bool = false) 原生的 autocomplete 属性，可选值为 true = off 或 false = on
```

Row栅格规则
-------

[](#row栅格规则)

- **Form::row**

```
 * @method $this gutter(Number $gutter) 栅格间距，单位 px，左右平分
 * @method $this type(String $type) 栅格的顺序，在flex布局模式下有效
 * @method $this align(String $align) flex 布局下的垂直对齐方式，可选值为top、middle、bottom
 * @method $this justify(String $justify) flex 布局下的水平排列方式，可选值为start、end、center、space-around、space-between
 * @method $this className(String $className) 自定义的class名称
```

参考: [view row栅格布局](http://v2.iviewui.com/components/grid#API)

Col栅格规则
-------

[](#col栅格规则)

- **Form::col**

```
 * @method $this span(Number $span) 栅格的占位格数，可选值为0~24的整数，为 0 时，相当于display:none
 * @method $this order(Number $order) 栅格的顺序，在flex布局模式下有效
 * @method $this offset(Number $offset) 栅格左侧的间隔格数，间隔内不可以有栅格
 * @method $this push(Number $push) 栅格向右移动格数
 * @method $this pull(Number $pull) 栅格向左移动格数
 * @method $this labelWidth(Number $labelWidth) 表单域标签的的宽度,默认150px
 * @method $this className(String $className) 自定义的class名称
 * @method $this xs(Number|Col $span)  其他type: text类型`Form::text`,password类型`Form::password`,textarea类型`Form::textarea`,url类型`Form::url`,email类型`Form::email`,date类型`Form::idate`

```
 * @method $this type(String $type) 输入框类型，可选值为 text、password、textarea、url、email、date;
 * @method $this size(String $size) 输入框尺寸，可选值为large、small、default或者不设置;
 * @method $this placeholder(String $placeholder) 占位文本
 * @method $this clearable(Boolean $bool) 是否显示清空按钮, 默认为false
 * @method $this disabled(Boolean $bool) 设置输入框为禁用状态, 默认为false
 * @method $this readonly(Boolean $bool) 设置输入框为只读, 默认为false
 * @method $this maxlength(int $length) 最大输入长度
 * @method $this icon(String $icon) 输入框尾部图标，仅在 text 类型下有效
 * @method $this rows(int $rows) 文本域默认行数，仅在 textarea 类型下有效, 默认为2
 * @method $this number(Boolean $bool) 将用户的输入转换为 Number 类型, 默认为false
 * @method $this autofocus(Boolean $bool) 自动获取焦点, 默认为false
 * @method $this autocomplete(Boolean $bool) 原生的自动完成功能, 默认为false
 * @method $this spellcheck(Boolean $bool) 原生的 spellcheck 属性, 默认为false
 * @method $this wrap(String $warp) 原生的 wrap 属性，可选值为 hard 和 soft, 默认为soft
 * @method $this autoSize($minRows, $maxRows) 自适应内容高度，仅在 textarea 类型下有效
```

#### 单选框组件

[](#单选框组件)

- **Form::radio**

```
 * @method $this size(String $size) 单选框的尺寸，可选值为 large、small、default 或者不设置
 * @method $this vertical(Boolean $bool) 是否垂直排列，按钮样式下无效
 * @method $this button() 使用按钮样式
 * @method $this required($message = null, $trigger = 'change') 设为必选
```

#### 评分组件

[](#评分组件)

- **Form::rate**

```
 * @method $this count(int $star) star 总数, 默认为 5
 * @method $this allowHalf(Boolean $bool) 是否允许半选, 默认为 false
 * @method $this disabled(Boolean $bool) 是否只读，无法进行交互, 默认为
 * @method $this showText(Boolean $bool) 是否显示提示文字, 默认为 false
 * @method $this clearable(Boolean $bool) 是否可以取消选择, 默认为 false
```

#### select选择框组件

[](#select选择框组件)

- **Form::select** 选择框
- **Form::selectMultiple** select选择框,多选,value为array类型
- **Form::selectOne** select选择框,单选

```
 * @method $this multiple(Boolean $bool) 是否支持多选, 默认为false
 * @method $this disabled(Boolean $bool) 是否禁用, 默认为false
 * @method $this clearable(Boolean $bool) 是否可以清空选项，只在单选时有效, 默认为false
 * @method $this filterable(Boolean $bool) 是否支持搜索, 默认为false
 * @method $this size(String $size) 选择框大小，可选值为large、small、default或者不填
 * @method $this placeholder(String $placeholder) 占位文本
 * @method $this transfer(String $transfer) 是否将弹层放置于 body 内，在 Tabs、带有 fixed 的 Table 列内使用时，建议添加此属性，它将不受父级样式影响，从而达到更好的效果, 默认为false
 * @method $this placement(String $placement) 弹窗的展开方向，可选值为 bottom 和 top, 默认为bottom
 * @method $this notFoundText(String $text) 当下拉列表为空时显示的内容, 默认为 无匹配数据
 * @method $this required($message = null, $trigger = 'change') 设为必选
```

#### 滑块组件

[](#滑块组件)

- **Form::slider** 滑块组件
- **Form::sliderRange** 滑块组件,区间选择,

```
 * @method $this min(float $min) 最小值, 默认 0
 * @method $this max(float $max) 最大值, 默认 100
 * @method $this step(float $step) 步长，取值建议能被（max - min）整除, 默认 1
 * @method $this disabled(Boolean $bool) 是否禁用滑块, 默认 false
 * @method $this range(Boolean $bool) 是否开启双滑块模式, 默认
 * @method $this showInput(Boolean $bool) 是否显示数字输入框，仅在单滑块模式下有效, 默认 false
 * @method $this showStops(Boolean $bool) 是否显示间断点，建议在 step 不密集时使用, 默认 false
 * @method $this showTip(String $tip) 提示的显示控制，可选值为 hover（悬停，默认）、always（总是可见）、never（不可见）
 * @method $this inputSize(String $size) 数字输入框的尺寸，可选值为large、small、default或者不填，仅在开启 show-input 时有效
```

#### 开关组件组件

[](#开关组件组件)

- **Form::switches**

```
 * @method $this size(String $size) 开关的尺寸，可选值为large、small、default或者不写。建议开关如果使用了2个汉字的文字，使用 large。
 * @method $this disabled(Boolean $bool) 禁用开关, 默认为false
 * @method $this trueValue(String $value) 选中时的值，默认为1
 * @method $this falseValue(String $value) 没有选中时的值，默认为0
 * @method $this openStr(String $open) 自定义显示打开时的内容
 * @method $this closeStr(String $close) 自定义显示关闭时的内容
```

#### 时间选择组件

[](#时间选择组件)

- **Form::timePicker** 时间选择组件
- **Form::time** 时间选择
- **Form::timeRange** 时间区间选择,value为array类型

```
 * @method $this type(String $type) 显示类型，可选值为 time、timerange
 * @method $this format(String $format) 展示的时间格式, 默认为HH:mm:ss
 * @method $this placement(String $placement) 时间选择器出现的位置，可选值为top, top-start, top-end, bottom, bottom-start, bottom-end, left, left-start, left-end, right, right-start, right-end, 默认为bottom-start
 * @method $this placeholder(String $placeholder) 占位文本
 * @method $this confirm(Boolean $bool) 是否显示底部控制栏, 默认为false
 * @method $this size(String $size) 尺寸，可选值为large、small、default或者不设置
 * @method $this disabled(Boolean $bool) 是否禁用选择器
 * @method $this clearable(Boolean $bool) 是否显示清除按钮
 * @method $this readonly(Boolean $bool) 完全只读，开启后不会弹出选择器，只在没有设置 open 属性下生效
 * @method $this editable(Boolean $bool) 文本框是否可以输入, 默认为false
 * @method $this transfer(Boolean $bool) 是否将弹层放置于 body 内，在 Tabs、带有 fixed 的 Table 列内使用时，建议添加此属性，它将不受父级样式影响，从而达到更好的效果, 默认为false
 * @method $this steps($h, $i = 0, $s = 0) 下拉列表的时间间隔，数组的三项分别对应小时、分钟、秒, 例如设置为 [1, 15] 时，分钟会显示：00、15、30、45。
```

#### 上传组件

[](#上传组件)

- **Form::upload** 上传组件
- **Form::uploadImages** 多图上传组件,value为array类型
- **Form::uploadFiles** 多文件上传组件,value为array类型
- **Form::uploadImageOne** 单图上传组件
- **Form::uploadFileOne** 单文件上传组件

```
 * @method $this uploadType(String $uploadType) 上传文件类型，可选值为 image（图片上传），file（文件上传）
 * @method $this action(String $action) 上传的地址
 * @method $this multiple(Boolean $bool) 是否支持多选文件
 * @method $this name(String $name) 上传的文件字段名
 * @method $this accept(String $accept) 接受上传的文件类型
 * @method $this maxSize(int $size) 文件大小限制，单位 kb
 * @method $this withCredentials(Boolean $bool) 支持发送 cookie 凭证信息, 默认为false
 * @method $this maxLength(Int $length) 最大上传文件数, 0为无限
 * @method $this headers(array $headers) 设置上传的请求头部
 * @method $this format(array $format) 支持的文件类型，与 accept 不同的是，format 是识别文件的后缀名，accept 为 input 标签原生的 accept 属性，会在选择文件时过滤，可以两者结合使用
 * @method $this data(array $data) 上传时附带的额外参数
 * @method $this required($message = null, $trigger = 'change') 设为必选
```

#### 树型组件

[](#树型组件)

- **Form::tree** 树型组件
- **Form::treeSelected** 选中类型,value为array类型,当`type=selected`并且`multiple=false`,值为String或Number类型
- **Form::treeChecked** 选择类型,value为array类型

```
 * @method $this type(String $type) 类型，可选值为 checked、selected
 * @method $this multiple(Boolean $bool) 是否支持多选,当`type=selected`并且`multiple=false`,默认为false,值为String或Number类型，其他情况为Array类型
 * @method $this showCheckbox(Boolean $bool) 是否显示多选框,默认为false
 * @method $this emptyText(String $emptyText) 没有数据时的提示,默认为'暂无数据'
 * @method $this data(array $treeData) 设置可选的data,**id必须唯一**
 * @method $this jsData($var) 设置data为js变量
```

树型组件data数据类 TreeData
--------------------

[](#树型组件data数据类-treedata)

- **Form::treeData** 树型组件data

```
 * @method $this id(String $id) Id,必须唯一
 * @method $this title(String $title) 标题
 * @method $this expand(Boolean $bool) 是否展开直子节点,默认为false
 * @method $this disabled(Boolean $bool) 禁掉响应,默认为false
 * @method $this disableCheckbox(Boolean $bool) 禁掉 checkbox
 * @method $this selected(Boolean $bool) 是否选中子节点
 * @method $this checked(Boolean $bool) 是否勾选(如果勾选，子节点也会全部勾选)
 * @method $this children(array $children) 批量设置子集
 * @method $this child(TreeData $child) 设置子集
```

所有组件生成效果
--------

[](#所有组件生成效果)

[![https://raw.githubusercontent.com/xaboy/laravel-form-builder/master/images/components.png](https://raw.githubusercontent.com/xaboy/laravel-form-builder/master/images/components.png)](https://raw.githubusercontent.com/xaboy/laravel-form-builder/master/images/components.png)

参考
--

[](#参考)

- **ui框架:** [iview2.x](http://v2.iviewui.com/docs/guide/install)
- **js表单生成器生成:** [form-create](https://github.com/xaboy/form-create)
- **php通用版生成器生成:** [form-builder](https://github.com/xaboy/form-builder)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Total

5

Last Release

2638d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bfc1dbf8cebcd0dc870cbaa6bb0ac7d20499acff2fe8fea03424ca407efaee61?d=identicon)[xaboy](/maintainers/xaboy)

---

Top Contributors

[![xaboy](https://avatars.githubusercontent.com/u/21242408?v=4)](https://github.com/xaboy "xaboy (17 commits)")

---

Tags

form-createform-generatorlaravellaravel-5-packagelaravelformform generatorform-builderiview

### Embed Badge

![Health badge](/badges/xaboy-laravel-form-builder/health.svg)

```
[![Health](https://phpackages.com/badges/xaboy-laravel-form-builder/health.svg)](https://phpackages.com/packages/xaboy-laravel-form-builder)
```

###  Alternatives

[xaboy/form-builder

好用的PHP表单生成器，快速生成现代化的form表单,支持前后端分离。内置17种常用表单组件。目前在政务系统、OA系统、ERP系统、电商系统、流程管理等系统中已稳定应用。

76275.0k5](/packages/xaboy-form-builder)[inkvizytor/fluentform

Form builder for Laravel

3416.2k](/packages/inkvizytor-fluentform)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
