2017 © Pedro Peláez
 

library bootforms

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

image

ceddyg/bootforms

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  • Saturday, January 20, 2018
  • by Ceddy G.
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 106 Forks
  • 0 Open issues
  • 30 Versions
  • 50 % Grown

The README.md

Important: This package is not actively maintained. For bug fixes and new features, please fork., (*1)

BootForms

This Project Has Been Deprecated. Code Climate Coverage Status, (*2)

BootForms builds on top of my more general Form package by adding another layer of abstraction to rapidly generate markup for standard Bootstrap 3 forms. Probably not perfect for your super custom branded ready-for-release apps, but a huge time saver when you are still in the prototyping stage!, (*3)

Installing with Composer

You can install this package via Composer by running this command in your terminal in the root of your project:, (*4)

composer require ceddyg/bootforms

Laravel

If you are using Laravel 4 or 5, you can get started very quickly by registering the included service provider., (*5)

Modify the providers array in config/app.php to include the BootFormsServiceProvider:, (*6)

'providers' => [
    //...
    'AdamWathan\BootForms\BootFormsServiceProvider'
  ],

Add the BootForm facade to the aliases array in config/app.php:, (*7)

'aliases' => [
    //...
    'BootForm' => 'AdamWathan\BootForms\Facades\BootForm'
  ],

You can now start using BootForms by calling methods directly on the BootForm facade:, (*8)

BootForm::text('Email', 'email');

Outside of Laravel

Usage outside of Laravel is a little trickier since there's a bit of a dependency stack you need to build up, but it's not too tricky., (*9)

$formBuilder = new AdamWathan\Form\FormBuilder;

$formBuilder->setOldInputProvider($myOldInputProvider);
$formBuilder->setErrorStore($myErrorStore);
$formBuilder->setToken($myCsrfToken);

$basicBootFormsBuilder = new AdamWathan\BootForms\BasicFormBuilder($formBuilder);
$horizontalBootFormsBuilder = new AdamWathan\BootForms\HorizontalFormBuilder($formBuilder);

$bootForm = new AdamWathan\BootForms\BootForm($basicBootFormsBuilder, $horizontalBootFormsBuilder);

Note: You must provide your own implementations of AdamWathan\Form\OldInputInterface and AdamWathan\Form\ErrorStoreInterface when not using the implementations meant for Laravel., (*10)

Using BootForms

Basic Usage

BootForms lets you create a label and form control and wrap it all in a form group in one call., (*11)

//  <form method="POST">
//    <div class="form-group">
//      <label for="field_name">Field Label</label>
//      <input type="text" class="form-control" id="field_name" name="field_name">
//    </div>
//  </form>
{!! BootForm::open() !!}
{!! BootForm::text('Field Label', 'field_name') !!}
{!! BootForm::close() !!}

Note: Don't forget to open() forms before trying to create fields! BootForms needs to know if you opened a vertical or horizontal form before it can render a field, so you'll get an error if you forget., (*12)

Customizing Elements

If you need to customize your form elements in any way (such as adding a default value or placeholder to a text element), simply chain the calls you need to make and they will fall through to the underlying form element., (*13)

Attributes can be added either via the attribute method, or by simply using the attribute name as the method name., (*14)

// 

// // //
BootForm::text('First Name', 'first_name')->placeholder('John Doe'); //
// // //
BootForm::select('Color', 'color')->options(['red' => 'Red', 'green' => 'Green'])->select('green'); // < form method="GET" action="/users"> BootForm::open()->get()->action('/users'); //
// // //
BootForm::text('First Name', 'first_name')->defaultValue('John Doe');

For more information about what's possible, check out the documentation for my basic Form package., (*15)

Reduced Boilerplate

Typical Bootstrap form boilerplate might look something like this:, (*16)

<form>
  <div class="form-group">
    <label for="first_name">First Name</label>
    <input type="text" class="form-control" name="first_name" id="first_name">
  </div>
  <div class="form-group">
    <label for="last_name">Last Name</label>
    <input type="text" class="form-control" name="last_name" id="last_name">
  </div>
  <div class="form-group">
    <label for="date_of_birth">Date of Birth</label>
    <input type="date" class="form-control" name="date_of_birth" id="date_of_birth">
  </div>
  <div class="form-group">
    <label for="email">Email address</label>
    <input type="email" class="form-control" name="email" id="email">
  </div>
  <div class="form-group">
    <label for="password">Password</label>
    <input type="password" class="form-control" name="password" id="password">
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

BootForms makes a few decisions for you and allows you to pare it down a bit more:, (*17)

{!! BootForm::open() !!}
  {!! BootForm::text('First Name', 'first_name') !!}
  {!! BootForm::text('Last Name', 'last_name') !!}
  {!! BootForm::date('Date of Birth', 'date_of_birth') !!}
  {!! BootForm::email('Email', 'email') !!}
  {!! BootForm::password('Password', 'password') !!}
  {!! BootForm::submit('Submit') !!}
{!! BootForm::close() !!}

Automatic Validation State

Another nice thing about BootForms is that it will automatically add error states and error messages to your controls if it sees an error for that control in the error store., (*18)

Essentially, this takes code that would normally look like this:, (*19)

<div class="form-group {!! $errors->has('first_name') ? 'has-error' : '' !!}">
  <label for="first_name">First Name</label>
  <input type="text" class="form-control" id="first_name">
  {!! $errors->first('first_name', '<p class="help-block">:message</p>') !!}
</div>

And reduces it to this:, (*20)

{!! BootForm::text('First Name', 'first_name') !!}

...with the has-error class being added automatically if there is an error in the session., (*21)

Horizontal Forms

To use a horizontal form instead of the standard basic form, simply swap the BootForm::open() call with a call to openHorizontal($columnSizes) instead:, (*22)


// Width in columns of the left and right side // for each breakpoint you'd like to specify. $columnSizes = [ 'sm' => [4, 8], 'lg' => [2, 10] ]; {!! BootForm::openHorizontal($columnSizes) !!} {!! BootForm::text('First Name', 'first_name') !!} {!! BootForm::text('Last Name', 'last_name') !!} {!! BootForm::text('Date of Birth', 'date_of_birth') !!} {!! BootForm::email('Email', 'email') !!} {!! BootForm::password('Password', 'password') !!} {!! BootForm::submit('Submit') !!} {!! BootForm::close() !!}

Additional Tips

Hiding Labels

You can hide labels by chaining the hideLabel() helper off of any element definition., (*23)

BootForm::text('First Name', 'first_name')->hideLabel(), (*24)

The label will still be generated in the markup, but hidden using Bootstrap's .sr-only class, so you don't reduce the accessibility of your form., (*25)

Help Blocks

You can add a help block underneath a form element using the helpBlock() helper., (*26)

BootForm::text('Password', 'password')->helpBlock('A strong password should be long and hard to guess.'), (*27)

Note: This help block will automatically be overridden by errors if there are validation errors., (*28)

Model Binding

BootForms makes it easy to bind an object to a form to provide default values. Read more about it here., (*29)

BootForm::open()->action( route('users.update', $user) )->put()
BootForm::bind($user)
BootForm::close()

The Versions

20/01 2018

dev-master

9999999-dev

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

20/01 2018

v0.12.0

0.12.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

19/01 2018

v0.11.0

0.11.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

16/01 2018

v0.10.0

0.10.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

18/07 2017

v0.9.0

0.9.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

26/04 2017

v0.8.5

0.8.5.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

31/01 2017

v0.8.4

0.8.4.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

19/01 2017

v0.8.3

0.8.3.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

20/09 2016

v0.8.2

0.8.2.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

09/06 2016

v0.8.1

0.8.1.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

28/02 2016

dev-aw-updates-for-form-0.9

dev-aw-updates-for-form-0.9

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

11/02 2016

v0.8.0

0.8.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

08/12 2015

v0.7.1

0.7.1.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

02/12 2015

dev-aw-group-wrapper-targets

dev-aw-group-wrapper-targets

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

10/09 2015

v0.7.0

0.7.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

12/06 2015

v0.6.3

0.6.3.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

11/06 2015

v0.6.2

0.6.2.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

09/06 2015

v0.6.1

0.6.1.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

01/05 2015

dev-input-groups

dev-input-groups

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

30/04 2015

v0.6.0

0.6.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

15/04 2015

v0.5.0

0.5.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

15/04 2015

dev-aw-custom-breakpoint-columns

dev-aw-custom-breakpoint-columns

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

07/02 2015

v0.4.2

0.4.2.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

29/09 2014

v0.4.1

0.4.1.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

17/09 2014

v0.4.0

0.4.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

12/08 2014

v0.3.1

0.3.1.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

11/08 2014

dev-dev

dev-dev

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

13/07 2014

v0.3.0

0.3.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

24/03 2014

v0.2

0.2.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Wathan

09/10 2013

v0.1

0.1.0.0

Just a Formbuilder with some Bootstrap specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.

  Sources   Download

The Requires

 

The Development Requires

by Adam Wathan