2017 © Pedro Peláez
 

library form

Berlioz Form

image

berlioz/form

Berlioz Form

  • Saturday, July 28, 2018
  • by ElGigi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 183 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 2 Versions
  • 25 % Grown

The README.md

Berlioz Form

Latest Version Software license Build Status Quality Grade Total Downloads, (*1)

Berlioz Form is a PHP library to manage your forms., (*2)

Installation

Composer

You can install Berlioz Form with Composer, it's the recommended installation., (*3)

$ composer require berlioz/form

Dependencies

  • PHP ^8.0
  • Packages:
    • berlioz/helpers
    • psr/http-message

Description

3 types of elements exists in Berlioz Form:, (*4)

  • AbstractType: it's a form control
  • Group: represents an object in OOP
  • Collection: represents a collection of AbstractType or Group

Input types available:, (*5)

  • Button
  • Checkbox
  • Choice
  • Date
  • DateTime
  • Email
  • File
  • Hidden
  • Month
  • Number
  • Password
  • Range
  • Reset
  • Search
  • Submit
  • Tel
  • Text
  • TextArea
  • Time
  • Url
  • Week

Usage

Form creation

Constructor of Form object accept 3 parameters:, (*6)

  • Name of form
  • Mapped object
  • Array of options

Example:, (*7)

$form = new Form('my_form', null, ['method' => 'post']);

Declare form control

add method accept 3 parameters:, (*8)

  • Name of control (must be the same that the mapped element)
  • Type (class name or object)
  • Array of options

Options are different between controls., (*9)

Example:, (*10)

$form->add('my_control', Text::class, ['label' => 'My control']);

Handle

Berlioz Form implements PSR-7 (HTTP message interfaces). You must give the server request to the handle method., (*11)

$form = new Form('my_form', null, ['method' => 'post']);
// ...

$form->handle($request);

if ($form->isSubmitted() && $form->isValid()) {
    // ...
}

Group

Example for an postal address:, (*12)

$addressGroup = new Group(['type' => 'address']);
$addressGroup
    ->add('address', Text::class, ['label' => 'Address'])
    ->add(
        'address_next',
        Text::class,
        ['label' => 'Address (next)',
         'required' => false]
    )
    ->add('postal_code', Text::class, ['label' => 'Postal code'])
    ->add('city', Text::class, ['label' => 'City']);

$form->add('address', $addressGroup);

Collection

Example for a list of addresses:, (*13)

// Create group
$addressGroup = new Group(['type' => 'address']);
$addressGroup
    ->add('address', Text::class, ['label' => 'Address'])
    ->add(
        'address_next',
        Text::class,
        ['label' => 'Address (next)',
         'required' => false]
    )
    ->add('postal_code', Text::class, ['label' => 'Postal code'])
    ->add('city', Text::class, ['label' => 'City']);

// Create collection
$collection = new Collection([
    'prototype' => $addressGroup,
    'data_type' => ArrayObject::class
]);

// Add collection to form
$form->add('addresses', $collection);

The Versions

28/07 2018

dev-refactoring

dev-refactoring http://www.berlioz-framework.com

Berlioz Form

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ronan Giron

12/07 2018

dev-develop

dev-develop http://www.berlioz-framework.com

Berlioz Form

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ronan Giron