There is no license information available for the latest version (0.2.1) of this package.

Helper for creating forms in laravel

0.2.1 2016-03-15 15:56 UTC

This package is auto-updated.

Last update: 2020-05-17 15:56:10 UTC


Laravel Helper module for creating forms and input fields Version 0.2 Beta


  • 0.2 beta - Rewritten from scratch, not compatible with previus versions


  1. Require with composer
composer require plokko/formbuilder
  1. Add the provider and facades in the app config file /config/app.php
'providers' => [
'aliases' => [
    'FormBuilder'=> plokko\FormBuilder\Facades\FormBuilder::class,


  • create the FormBuilder instance First create a new instance of FormBuilder in your view with the make command and assign it to a variable

The make function accepts the same parameters as laravelcollective/html Form::open

  • declaring the fields You can then add fields using the requested field type as method name and field name as value
$fb->text('text_field'); //Input field (type=text)
$fb->email('email_field);//Email input field (type=email)
  • Accessing the fields

To set the options to the field you can access the field when declared


or you can retrieve it later by accessing it by name as a parameter or array

$fb->field_required->value('My value');

If you try to access and undeclared field the field will be automatically declared as a text field

// Equals to: //
  • Render the form

To render the form you should first open and close the form using the openForm() and closeForm() functions, rendering the fields with the render() function between them.

{!! $fb->openForm() !!}
    <!--render the fields/-->
    {!! $fb->render() !!}
    <!--Add some basic submit buttons-->
    <button type=submit>Submit</button>
    <button type=reset>Reset</button>
{!! $fb->closeForm() !!}


Form view

You can specify how the form will be rendered by applying a view to the FormBuilder class


You can specify the view like following where $fields is an array containing all the defined fields

/**@var array $fields**/
@foreach($fields AS $field)
    <?/**@var \plokko\FormBuilder\FormField $field**/?>
    <div class="form-group">
        {!! $field->label->render()!!}
            <?$field->addClass('form-control');/*Add class except for radio or checkbox fields*/?>
        {!! $field->render() !!}


The view will be called with the render function.

Expanding functionalities

You can easly add or replace field types by changing the config file; to do so first publish the config

php artisan vendor:publish

Then edit the /config/app.php file

return [
    /** Default view for FormBuilder **/
    /** Registered FormField providers as type=>classname **/
        'select'    => plokko\FormBuilder\fields\SelectField::class,

        'text'      => plokko\FormBuilder\fields\InputField::class,
        'email'     => plokko\FormBuilder\fields\InputField::class,
        'hidden'    => plokko\FormBuilder\fields\InputField::class,
        'number'    => plokko\FormBuilder\fields\InputField::class,
        'password'  => plokko\FormBuilder\fields\InputField::class,

        'file'      => plokko\FormBuilder\fields\FileField::class,

        'radio'     => plokko\FormBuilder\fields\CheckboxField::class,
        'checkbox'  => plokko\FormBuilder\fields\CheckboxField::class,

        'textarea'  => plokko\FormBuilder\fields\InputField::class,
        'select2'    => plokko\FormBuilder\fields\Select2Field::class,


You can create a new field type by expanding the plokko\FormBuilder\fields\FormField class like so:

namespace mynamespace;

use plokko\FormBuilder\fields\FormField;

class MyCustomField extends FormField
    function myFunction()
        return $this;

and then adding it in the config file like so

return [
    /** Default view for FormBuilder **/
    /** Registered FormField providers as type=>classname **/

You can then add the field using the declared name: