Download the PHP package bupy7/php-html-form without Composer
On this page you can find all versions of the php package bupy7/php-html-form. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bupy7/php-html-form
More information about bupy7/php-html-form
Files in bupy7/php-html-form
Package php-html-form
Short Description A basic framework agnostic form building package with a few extra niceties like remembering old input and retrieving error messages.
License MIT
Informations about the package php-html-form
php-html-form
This is fork of adamwathan/form. There is just HTML-elements builder without any framework support. Extension are supporting PHP from 5.6 to 8.x!
Boring name for a boring package. Builds form HTML with a fluent-ish, hopefully intuitive syntax.
- Installation
- Basic Usage
- Error Messages
- CSRF Protection
- Data Binding
Installation
You can install this package via Composer by running this command in your terminal in the root of your project:
Basic Usage
- Getting Started
- Opening a Form
- Text and Password Fields
- Textareas
- Checkboxes and Radio Buttons
- Selects
- Buttons
- Hidden Inputs
- Labels
- Setting Attributes
Getting Started
First, instantiate a FormBuilder...
Next, use the FormBuilder to build an element. For example:
- All elements support method chaining, so you can add as many options to an element as you need.
- All elements implement
__toString()
so there is no need to manually render.
Opening a Form
Text and Password Fields
Text and password fields share the same interface.
Other available methods:
placeholder($string)
optional()
defaultValue($string)
disable()
enable()
Textareas
Textareas share the same interface as regular text fields, with a couple of extra useful methods.
Checkboxes and Radio Buttons
Selects
Buttons
Hidden Inputs
Labels
Basic Label
Wrapping another element
Setting Attributes
Error Messages
FormBuilder also allows you to easily retrieve error messages for your form elements. To do so, just
implement the ErrorStoreInterface
and pass it to the FormBuilder:
You can also supply a format
parameter to getError()
to cleanup your markup. Instead of doing this:
...you can simply do this, which will display the formatted message if it exists, or nothing otherwise.
CSRF Protection
Assuming you set a CSRF token when instantiating the FormBuilder, add a CSRF token to your form easily like so:
Data Binding
Sometimes you might have a form where all of the fields match properties on some sort of object or array in your system, and you want the user to be able to edit that data. Data binding makes this really easy by allowing you to bind an object or array to your form that will be used to automatically provide all of the default values for your fields.
Note: Be sure to
bind
before creating any other form elements.
Testing
Run tests:
Run tests with coverage:
HTML coverage path: build/coverage/index.html
Code style
To fix code style, run:
You have to install PHP CS Fixer at first, if you don't use build-in Docker image:
License
php-html-form is released under the MIT License.