estey / formbuilder
Laravel 4 extended FormBuilder Class.
Requires
- php: >=5.4.0
- illuminate/html: 4.2.x
- illuminate/translation: 4.2.x
Requires (Dev)
- illuminate/http: 4.2.x
- illuminate/routing: 4.2.x
- mockery/mockery: dev-master
- phpunit/php-code-coverage: ~2.0
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: ~1.5
README
This class extends Laravel 4's FormBuilder class adding a selectWeekday
method, translations to selectWeekday
and selectMonth
, and adds the ability to prepend an array of options to select fields.
Installation
Install this package through Composer by editing your project's composer.json
file to require estey/formbuilder
.
{ "require": { "estey/formbuilder": "4.2.*" } }
Then, update Composer:
composer update
Open app/config/app.php
, and replace 'Illuminate\Html\HtmlServiceProvider'
with:
'Estey\FormBuilder\HtmlServiceProvider'
Usage
selectWeekday
The selectWeekday
method allows you to quickly generate a select field with a list of weekdays.
selectWeekday('weekday');
Will return:
<select name="weekday"> <option value="1">Sunday</option> <option value="2">Monday</option> <option value="3">Tuesday</option> <option value="4">Wednesday</option> <option value="5">Thursday</option> <option value="6">Friday</option> <option value="7">Saturday</option> </select>
Translations
The selectWeekday
and selectMonth
methods in this extension will respect the locale settings. For example, to use Spanish, create an app/lang/es
directory and copy over the example datetime file from this package /src/lang/es/datetime.php
to app/lang/es/datetime.php
. After setting the locale to 'es' in app/config/app.php
, selectWeekday()
should return:
<select> <option value="1">domingo</option> <option value="2">lunes</option> <option value="3">martes</option> <option value="4">miércoles</option> <option value="5">jueves</option> <option value="6">viernes</option> <option value="7">sábado</option> </select>
Prepend Options
To prepend options to a selectWeekday
and selectMonth
method, add a _prepend
array to the options array.
selectMonth('month', '', [ 'id' => 'foo', '_prepend' => ['' => '-- Choose a Month --'] ]);
Will return:
<select name="month" id="foo"> <option value="" selected="selected">-- Choose a Month --</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select>
License
The MIT License (MIT). Please see License File for more information.