Download the PHP package thomasleconte/form-generator without Composer
On this page you can find all versions of the php package thomasleconte/form-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thomasleconte/form-generator
More information about thomasleconte/form-generator
Files in thomasleconte/form-generator
Package form-generator
Short Description PHP form generator compatible with Doctrine
License MIT
Informations about the package form-generator
Form generator
composer require thomasleconte/form-generator
This is a library that make you able to generate a form. This library use reflection principle to generate the best result from a class name or an existing object.
This form generator is compatible with Doctrine ORM. In fact, if one of your property doesn't have a PHP type, but a Doctrine type annotation, it will take this one.
Moreover, in the case of a select list generation, you can fill the list with Doctrine by specifying class name, key attribute and attribute value.
Check this out !
Summary
Construction
Basic generation
Personalize inputs
Personalize form
Surround your inputs / form
Special inputs
Hydrate dynamically select field
Construction
By default, constructor doesn't need arguments. But you can provide a current Doctrine EntityManager instance.
If you installed Doctrine but you did not provide EntityManager instance to generator, it will try to get it from
bootstrap.phpfile at root of your project. This file is generally provided by most of Doctrine tutorials online, and return an instance of Doctrine EntityManager.
For more informations, check this tutorial.
Basic generation
Or with a current object :
You can add attribute to a field after generated a form. Update is also available :
Personalize your inputs
By default, all inputs just have an auto-generated name attribute. But you can give them all attributes that you want. Imagine you want to add a class to firstname input of our User class used before :
You can also decide to hide one of fields. By default, "id" field of your entity is hidden and you can't override it. You can hide others one with "hide" field option : ``
Personalize your form
Like inputs personalization, you can add all attributes that you want, just like that :
Surround your inputs / form
You can surround generation result of each inputs or form for give them div parent for example. When you use it, you must provide {{content}} which corresponding to input of form generation result. Check this out :
-
Input surround
- Form surround
NB : For form surround, it surround inside of
<form>tags.
Special inputs
Sometimes you will want to use select or textarea tags inside your form. For use it, just precize type of input. For example, you want a textarea for firstname attribute and select list for age attribute of our User class. Check this out :
Select field
When you make a select field, you must provide a list of items, with a value key for differentiate each of them, and a name key to display. Check this example :
Moreover, you can fill items array with Doctrine. Instead of array, just give class name, and specify optionLabel / optionValue with attributes name of your class specified before. This is how to do :