Just a Formbuilder with some Bootstrap 4 specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.
typicms/bootforms
Just a Formbuilder with some Bootstrap 4 specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.
BootForms was originally created by Adam Wathan. It is build on top of the more general Form package by adding another layer of abstraction to rapidly generate markup for standard Bootstrap 5 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!, (*2)
You can now start using BootForms by calling methods directly on the BootForm facade:, (*7)
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., (*8)
$formBuilder = new TypiCMS\Form\FormBuilder;
$formBuilder->setOldInputProvider($myOldInputProvider);
$formBuilder->setErrorStore($myErrorStore);
$formBuilder->setToken($myCsrfToken);
$basicBootFormsBuilder = new TypiCMS\BootForms\BasicFormBuilder($formBuilder);
$horizontalBootFormsBuilder = new TypiCMS\BootForms\HorizontalFormBuilder($formBuilder);
$bootForm = new TypiCMS\BootForms\BootForm($basicBootFormsBuilder, $horizontalBootFormsBuilder);
Note: You must provide your own implementations of TypiCMS\Form\OldInputInterface and TypiCMS\Form\ErrorStoreInterface when not using the implementations meant for Laravel., (*9)
Using BootForms
Basic Usage
BootForms lets you create a label and form control and wrap it all in a form group in one call., (*10)
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., (*11)
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., (*12)
Attributes can be added either via the attribute method, or by simply using the attribute name as the method name., (*13)
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., (*19)
Essentially, this takes code that would normally look like this:, (*20)
âŠwith the is-invalid class being added automatically if there is an error in the session., (*22)
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:, (*23)
// 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., (*24)
The label will still be generated in the markup, but hidden using Bootstrapâs .visually-hidden class, so you donât reduce the accessibility of your form., (*25)
Form Text
You can add a text block underneath a form element using the formText() helper., (*26)
BootForm::text('Password', 'password')->formText('A strong password should be long and hard to guess.')
Model Binding
BootForms makes it easy to bind an object to a form to provide default values. Read more about it here., (*27)
Just a Formbuilder with some Bootstrap 4 specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.
Just a Formbuilder with some Bootstrap 4 specific conveniences. Remembers old input, retrieves error messages and handles all your boilerplate Bootstrap markup automatically.