Download the PHP package webservco/form without Composer
On this page you can find all versions of the php package webservco/form. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webservco/form
More information about webservco/form
Files in webservco/form
Package form
Short Description A PHP component/library. HTML forms with filters and validators, and error messages for both the form and each field.
License MIT
Homepage https://webserv.co
Informations about the package form
webservco/form
A PHP component/library. Please see webservco/sandbox for an example project using these types of components.
HTML forms with filters and validators, and error messages for both the form and each field.
- Related:
webservco/jsonapi-application(its request handler is a form too),webservco/view(templates that display the form)
Installation
Usage
Build the form in a factory. Each controller then gets its own instance.
In the controller:
In the template, $form->getErrors() has the form errors and $form->getField('name')->getErrors() has the errors for one field.
Contracts
| Interface | Implementation | Purpose |
|---|---|---|
Contract\FormInterface |
Service\HtmlPostForm (extends Service\AbstractForm) |
Reads POST data, filters and validates every field. |
Contract\FormFieldInterface |
Service\FormField |
One field: value, settings, filters, validators and errors. |
Contract\FormFilterInterface |
Service\Filter\TrimFilter, StripTagsFilter, NumberFilter |
Changes the value before validation. NumberFilter keeps only digits. |
Contract\FormValidatorInterface |
Service\Validator\RequiredValidator, MinimumLengthValidator, MaximumLengthValidator, EmailAddressValidator |
Checks the value and gives back its error when the check fails. |
Contract\FormFactoryInterface |
your factory | Creates the form. |
Namespaces are relative to WebServCo\Form\.
Notes
Form-level filters run before the field's own filters, and form-level validators run before the field's own validators. Every field gets all of them, and the length validators skip empty fields that aren't required.
A request that isn't POST gets a form error with code 405, and the form isn't marked as sent. An array in the POST data where a field expects a single value is rejected with a form error.
StripTagsFilter cleans input, but it doesn't make output safe. Escape values in templates as well.
Development
License
MIT