Download the PHP package mdbottino/forms without Composer
On this page you can find all versions of the php package mdbottino/forms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package forms
Forms
Easy, framework agnostic HTML form rendering. This is meant to render a form in a way that is reproducible, reusable and consistent.
There is no (and there will not be any) validation whatsoever. It only deals with making valid HTML fields and forms.
There is no (and there will not be any) integration to any framework, it uses associative arrays or stdClasses for prepopulating forms (like when you edit a database entity).
The goal is to use one (or a few) generic template(s) to render all fields in a consistent way.
Disclaimer: It does not have all HTML5 fields implemented and it does not do any validation of the attributes.
Installation
Usage
In order to use in a template (or plain PHP if you so desire) you have to subclass BaseForm and in the constructor do any needed configuration. The subclass' constructor must call the parent constructor and set the fields attribute. In the fields array you need to instantiate a specific field with name and label at a minimum.
Basic example:
The use of the $src variable is optional, it allows to populate the form with data if given. This allows for adding or editing records easily
The keys/properties must match the names of the fields given upon creation.
The fields are accessed through the method fields which returns the array of fields.
The label is rendered through the method label of each field. The widget is rendered through the method widget of each field.
The previous code would produce the following HTML:
Using a blade template it could look like this
It defaults to POST as method, no action and no enctype. If one of the fields is a FileField it will set the enctype to multipart/form-data. It can be overriden by using setAction, setMethod and setEnctype in the form.
Styling
Styling is as easy as it gets. The third and optional argument options supports a variety of keywords that changes the way the rendering behaves.
One of them is attrs, which equates to the attributes of the rendered field. If you give it a key named class it will display that value in the resulting HTML.
The resulting HTML will be:
Styling using a blade template could look like this:
Advanced usage
TODO
Examples
TODO