glynnforrest / reform
Create forms that render and validate with ease.
Installs: 1 026
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
Requires (Dev)
- glynnforrest/blockade: 0.2.*
- phpunit/phpunit: ~4.3
- symfony/event-dispatcher: ~2.4
- symfony/http-foundation: ~2.3
Suggests
- glynnforrest/blockade: Throw and handle security exceptions automatically
- symfony/event-dispatcher: (~2.4) Allow the sending of form events
- symfony/http-foundation: (~2.3) Submit forms automatically using a Request object
This package is not auto-updated.
Last update: 2022-02-01 12:33:39 UTC
README
Reform makes it easy to create forms in PHP. Create a form, add rows
and validation, then call render()
. Everything else is done
automatically - checking for submissions, validating data, setting
values, creating labels and error messages, handling CSRF...
For greater control, the form can be rendered row-by-row, or even in individual pieces. You can use only a few features without the rest getting in the way.
Features
- Many row types and validation rules. It is trivial to add custom types to match your requirements.
- Different renderers to apply styles to the form (e.g. Bootstrap). Changing the renderer can be done with a single line of code.
- Integration with Symfony HttpFoundation to automatically submit forms.
- Security measures like honeypot fields, timers, and CSRF protection. Add the Blockade security library to have these exceptions handled automatically.
- Events to customize how forms behave.
Quickstart
A simple form with a username and password field.
$form = new Reform\Form\Form('/login'); $form->text('username'); $form->password('password'); $form->submit('login'); echo $form->render();
Now with some validation.
$form = new Reform\Form\Form('/login'); $form->text('username') ->addRule(new Rule\Required('Did you forget your name?')) ->addRule(new Rule\Regex('`[A-z.]+`')) $form->password('password') ->addRule(new Rule\Required()); $form->submit('login');
Submit the form automatically by using a Symfony Request object. If the correct HTTP method was used and all fields have passed the required validation, the form is considered valid.
Valid or not, after a submission the fields are populated with the submitted data.
$request = Request::createFromGlobals(); $form->handle($request); if ($form->isValid()) { //the form was submitted correctly - the correct http method was //used and all validation rules passed //perform the login and redirect login_user(); redirect_to_home_page(); } //the form was either not submitted or failed the validation. $form //now has any submitted parameters bound to it, so all we need to do //is render the form again. Any values and errors will be added //automatically. echo $form->render();
See docs/
for further documentation.
Installation
Install using composer:
{ "require": { "glynnforrest/reform": "0.4.*" } }
Viewing the examples
composer install
cd examples/
bower install
php -S localhost:8000
Then visit localhost:8000
in your web browser.
These instructions assume you have composer, bower and PHP 5.4 installed.
License
MIT, see LICENSE for details.
Copyright 2014 Glynn Forrest