2017 © Pedro Peláez
 

library form

Dynamic form builder.

image

anlutro/form

Dynamic form builder.

  • Wednesday, August 12, 2015
  • by anlutro
  • Repository
  • 3 Watchers
  • 4 Stars
  • 112 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 2 Open issues
  • 24 Versions
  • 0 % Grown

The README.md

PHP Form Builder Build Status Latest Version

Sick of the bugs and quirks present in the default Laravel 4 form builder, I wrote my own and made it framework-agnostic. Features include:, (*1)

  • Each form is its own object with (optionally) its own behaviours
  • Set a model for the form object to pre-fill the form inputs with
  • Get old input from session
  • Validate input

WARNING: Backwards compatibility is not guaranteed during version 0.x., (*2)

Installation

composer require anlutro/form, (*3)

Pick the latest stable version from packagist or the GitHub tag list., (*4)

Laravel 4

Add 'anlutro\Form\ServiceProvider' to the list of providers in app/config/app.php., (*5)

Other frameworks/raw PHP

You will need to set up a shared instance of anlutro\Form\Builder, and this should be injected into all Form instances., (*6)

In order to get input from a Form instance, you should setRequest on the Builder instance. The request should be an instance of Symfony\Component\HttpFoundation\Request., (*7)

For old input from session, CSRF tokens and validation to work, you need to construct and set a session and/or validation service on the Builder instance. The interfaces are located in the Adapters namespace, and once you have an object that implements these you can set them via setSessionAdapter and setValidationAdapter., (*8)

If you have written an adapter for popular libraries, please consider a pull request so it can be added to the package!, (*9)

Usage

For simple forms, we'll use the class anlutro\Form\DefaultForm. Inject this into your controller..., (*10)

use anlutro\Form\DefaultForm;
public function __construct(DefaultForm $form)
{
    $this->form = $form;
}

Or just construct it, if you have an instance of the Form\Builder available., (*11)

$this->form = new DefaultForm($formBuilder);

In your controller action you can define the behaviour of the form. All of the following are optional., (*12)

// The model is where the form gets its data. It can be an existing active-
// record model, entity or an array of dummy data.
$this->form->setModel($myModel);
$this->form->setAction('http://mysite.com/my-route');
$this->form->setMethod('PUT');

Pass the form to your view in the controller action that shows the form. In your view - using whatever templating engine you have available:, (*13)

<?= $form->open(['class' => 'form-horizontal']) ?>
<div class="form-group">
  <?= $form->text('my_field', ['class' => 'form-control']) ?>
</div>
<?= $form->close() ?>

In the controller action that handles the POST request of the form:, (*14)

$input = $this->form->getInput();
$this->service->doStuff($input);

If your form has custom behaviour - getters, setters etc., you can extend the AbstractForm class and inject your custom class instead of the DefaultForm., (*15)

use anlutro\Form\AbstractForm;
class MyForm extends AbstractForm {}

Check the examples directory for more information., (*16)

Contact

Open an issue on GitHub if you have any problems or suggestions., (*17)

License

The contents of this repository is released under the MIT license., (*18)

The Versions

12/08 2015

dev-master

9999999-dev

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

12/08 2015

0.3.14

0.3.14.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

24/06 2015

0.3.13

0.3.13.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

24/06 2015

0.3.12

0.3.12.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

01/06 2015

0.3.11

0.3.11.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

15/05 2015

0.3.10

0.3.10.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

24/09 2014

0.3.9

0.3.9.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

23/09 2014

0.3.8

0.3.8.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

09/07 2014

0.3.7

0.3.7.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

27/05 2014

0.3.6

0.3.6.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

27/05 2014

0.3.5

0.3.5.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

27/05 2014

0.3.4

0.3.4.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

07/05 2014

0.3.3

0.3.3.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

15/04 2014

0.3.2

0.3.2.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

31/03 2014

0.3.1

0.3.1.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

29/03 2014

0.3.0

0.3.0.0

Dynamic form builder.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

29/03 2014

0.2.3

0.2.3.0

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

28/03 2014

0.2.2

0.2.2.0

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

28/03 2014

0.2.1

0.2.1.0

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

26/03 2014

dev-develop

dev-develop

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

26/03 2014

0.2.0

0.2.0.0

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

26/03 2014

0.1.2

0.1.2.0

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

27/01 2014

0.1.1

0.1.1.0

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro

21/01 2014

0.1.0

0.1.0.0

Form builder improvements and additions for Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lutro