npmweb / laravel-forms
Extends Laravel's FormBuilder to lay out form elements for Bootstrap or Foundation
Installs: 1 870
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 4
Open Issues: 2
Requires
- laravel/framework: ~4.1 || ~5.0
- npmweb/client-validation-generator: ^2.0
Requires (Dev)
- mockery/mockery: dev-master@dev
README
Extends the laravelcollective/html
FormBuilder object (Form:: facade) to automatically output form fields with Foundation- or Bootstrap-specific wrapping markup around them.
Example
With foundationBasicGrid
selected, the following call:
{{ Form::text('name',null,['errors'=>$errors]) }}
Will output:
<div class="row">
<div class="medium-12 columns">
<label for="name">
Name
<input id="name" placeholder="Name" maxlength="150"
name="name" type="text" value="Parent Organization">
</label>
</div>
</div>
If there is a validation error on the field, it will output:
<div class="row">
<div class="medium-12 columns">
<label for="name">
Name
<input id="name" placeholder="Name" maxlength="150"
name="name" type="text" value="Parent Organization">
<small class="error">The img field is required.</small>
</label>
</div>
</div>
You can easily change the grid column classes, and if you use bootstrapBasicGrid
the equivalent Bootstrap 3 markup will be used.
Installation
- Require
"npmweb/laravel-forms": "^2.0"
in yourcomposer.json
file. - Run
composer install
orcomposer update
to download it and have the autoloader updated.3. - Open
app/config/app.php
and make the following changes under theproviders
key: a. If'Collective\Html\HtmlServiceProvider'
is there, comment it out b. Add'NpmWeb\FormBuilder\HtmlServiceProvider'
Configuration
You will probably want to change the default configuration. First, publish the package config file:
$ php artisan vendor:publish --provider="NpmWeb\FormBuilder\HtmlServiceProvider"
The following options are available:
'driver'
: Defaults to'foundationBasicGrid'
(Foundation 5) but can also be set to'bootstrapBasicGrid'
(Bootstrap 3). This changes what markup is generated to fit with the given CSS framework's default form layout.'col_width'
: The grid class for the form field's container element. For example, in Foundation'large-6'
will make the container take up 6 out of 12 columns.'row_per_field'
: Defaults tofalse
, in which case each form field is outputted directly, and you have to wrap it in a row yourself. If you set it totrue
, each form field container is wrapped in a row, forcing it to be one field per row.
Here's some more information about the included drivers:
- foundationBasicGrid: Uses the basic Foundation form markup, with a
<label>
tag wrapping the inputs. Layed out within a grid row and column. - bootstrapBasicGrid: Uses the basic Bootstrap form markup, with a
<label>
tag as a prior-child of the input. Layed out within a grid row and column.
Usage
Just use any of Laravel's normal Form::
methods, such as Form::text()
or Form::select()
. Instead of outputting the bare form control, it will also output the wrapping DOM elements appropriate to your selected CSS framework.
Additionally, a Form::readonly()
method has been added. This outputs a read-only value wrapped in the same DOM elements, allowing you to include read-only "fields" in your forms.
License
This code is released under the MIT License. See the LICENSE file for details.