kilrizzy/bootforms

生成用于Twitter Bootstrap的HTML表单结构

dev-master 2013-12-09 14:42 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:55:51 UTC


README

##注意!

我创建这个包是为了简化我的项目,从那时起,我发现了一个似乎能够实现bootforms目标并且功能更全面的包。

强烈建议您查看Anahkiasen/former,看看它是否更适合您的项目

Bootforms

Laravel 4的Bootstrap表单字段生成器。Bootforms将为您的表单字段添加“控件”、“标签”和“分组”HTML元素,以使与Bootstrap的集成更快更简单。

将这个

{{ Bootform::field(array(
  'label'       => "Full Name",
  'name'        => "name",
)) }}
{{ Bootform::field(array(
	'label'       => "Email Address",
	'name'        => "email",
	'input-prepend' => '<i class="icon-envelope"></i>',
	'input-attributes' => array('placeholder' => "example@example.com"),
	'input-class' => "input-large"
  )) }}

变成这个

<div class="control-group field-group-text control-group-name">
  <label for="name" class="control-label ">Full Name</label>
  <div class="controls" >
    <input class="" name="name" type="text" value="">
  </div>
</div>
<div class="control-group  field-group-text control-group-email">
  <label for="email" class="control-label ">Email Address</label>
  <div class="controls input-prepend" >
    <span class="add-on"><i class="icon-envelope"></i></span>
    <input class="input-large" placeholder="example@example.com" name="email" type="text" value="">
  </div>
</div>

Bootforms使用Laravel的表单类来生成表单字段。

安装

kilrizzy/bootforms添加到composer.json中。

"kilrizzy/bootforms": "dev-master"

运行composer update以获取Bootforms的最新版本。

打开app/config/app.php并添加服务提供者

'Kilrizzy\Bootforms\BootformsServiceProvider',

app/config/app.php中添加别名

'Bootform' => 'Kilrizzy\Bootforms\BootformsFacade',

用法

将字段数据数组传递给Bootforms,以使用以下选项生成HTML

$options = array(
  'type' => "text", //field input type (text, textarea, password, select, checkbox, radio, file)
  'name' => "", //field input name
  'id' => "", //field input id
  'value' => "", //field input value
  'label' => "", //field label
  'help' => "", //field help display text
  'label-class' => "", //label class
  'group' => true, //wrap group
  'group-class' => "", //class applied to the group container
  'group-attributes' => array(), //additional group attributes
  'controls' => true, //wrap controls
  'controls-class' => "", //class applied to the controls container
  'controls-attributes' => array(), //additional controls attributes
  'input-class' => "", //class applied to the input
  'input-attributes' => array(), //additional input attributes
  'input-prepend' => "", //prepend control data
  'input-append' => "", //append control data
);

请查看demo/bootforms.blade.php以获取示例视图

Bitdeli Badge