2017 © Pedro Peláez
 

library bricks

Flexible form builder with data validation and pre processing

image

misantron/bricks

Flexible form builder with data validation and pre processing

  • Monday, March 5, 2018
  • by misantron
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Bricks

Build Status Code Coverage Scrutinizer Code Quality Packagist PHP 7 Support, (*1)

Flexible form builder with data validation and pre processing., (*2)

Installation

Run Composer from command line:, (*3)

composer require misantron/bricks

Or add dependency to composer.json:, (*4)

{
    "require": {
        "misantron/bricks": "dev-master"
    }
}

Usage

Create a new form by inheriting \Bricks\AbstractForm. Abstract method fields() must be implemented with configuration array:, (*5)

class SomeForm extends \Bricks\AbstractForm
{
    protected funtion fields(): array
    {
        return [
            'foo' => [
                'type' => 'string', // using for data type cast
                'validators' => [
                    'required' => true,
                    'lengthMax' => 64,
                ],
            ],
            'bar' => [
                'type' => 'integer', // using for data type cast
                'validators' => [
                    'required' => true,
                    'in' => function () {
                        return [1, 2];
                    }
                ],
                'cleanup' => true, // flag that field will be deleted from getData() method call response
            ],
        ];
    }
}

Form workflow inside application controller/service/etc.:, (*6)

$request = Request::fromGlobals(); // must implements \Psr\Http\Message\RequestInterface

$default = [
    'foo' => 'test',
];

$form = \SomeForm::create()
    ->setData($default) // allows to pass an initial data before handling the request
    ->handleRequest($request) // get data from the request and data processing
    ->validate(); // data validation

$data = $form->getData(); // extracting processed and validated data from form

Built-in field types

string, integer, float, boolean, array (contains elements of different types), dateTime (transform datetime string or timestamp to Carbon object) , intArray, strArray, floatArray, (*7)

Custom user type can be easily added:, (*8)

class MyTransducer extends \Bricks\Data\Transducer
{
    private funtion myType($value)
    {
        // your custom logic here
    }
}

Built-in field validation rules

See Valitron documentation. If form data is not valid - \Bricks\Exception\ValidationException will be thrown:, (*9)

try {
    $form->validate();
} catch (\Bricks\Exception\ValidationException $e) {
    var_dump($e->getData()); // getting fields error data
}

The Versions

05/03 2018

dev-master

9999999-dev https://github.com/misantron/bricks

Flexible form builder with data validation and pre processing

  Sources   Download

MIT

The Requires

 

The Development Requires

php form builder

29/01 2018

v1.0.0

1.0.0.0 https://github.com/misantron/bricks

Flexible form builder with data validation and pre processing

  Sources   Download

MIT

The Requires

 

The Development Requires

php form builder

28/01 2018

v1.0.0-beta

1.0.0.0-beta https://github.com/misantron/bricks

Flexible form builder with data validation and pre processing

  Sources   Download

MIT

The Requires

 

The Development Requires

php form builder