Download the PHP package enriquejlicona/forms without Composer
On this page you can find all versions of the php package enriquejlicona/forms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package forms
Galahad/Forms
Build HTML forms with a fluent syntax.
- Installation
- Basic Usage
- Remembering Old Input
- 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:
Laravel
This package will be auto-discovered in Laravel 5.5.
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
Remembering Old Input
The FormBuilder can remember old input and prepopulate your form fields if you redirect back to the form because of a validation error.
To make this work, you must create a class that implements the OldInputInterface
and pass it to the FormBuilder:
Now, your form elements will automatically populate with the user's old input data if it is available.
This works well with the defaultValue()
methods, allowing you to set a default value that will be overridden by old input if the user has already submitted the form.
This package ships with a Laravel implementation out of the box, called
IlluminateOldInput
.
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:
This package ships with a Laravel implementation out of the box, called
IlluminateErrorStore
.
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 (or you are using Laravel), 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.
This will work out of the box with Laravel's Eloquent models.
When using data binding, old input will still take priority over any of your bound values, so you can still easily redirect the user back to the form with any validation errors without losing any of the data they entered.
Note: Be sure to
bind
before creating any other form elements.