okneloper / forms
Build, control, submit and validate forms, hassle free.
v0.10.5
2018-10-04 22:28 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- laravel/framework: >=5.2.0,<5.8.0
- phpunit/phpunit: ^4.0 || ^5.0
Suggests
- laravel/framework: Allows validating your forms with Laravel
- respect/validation: Allows validating your forms with Respect validation package
- dev-master
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.x-dev
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.x-dev
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.x-dev
- v0.7.1
- v0.7.0
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.0
This package is auto-updated.
Last update: 2025-01-05 19:51:47 UTC
README
- Can be integrated with any framework or non-framework code.
- Includes adapters for illuminate/validation and respect/validation.
Documentation and examples coming in further realeases.
A very simple example of a using a form with Illuminate/Validation
class Model { public $name; public $type; } $form = new \Okneloper\Forms\Form(new Model); $form->add('text', 'name', 'Name'); $form->add('select', 'type', 'Type')->options([ 'foo' => 'Bar', 'baz' => 'FooBar', ]); if ($request->isPost()) { $app = \Illuminate\Support\Facades\App::getFacadeApplication(); $rules = [ 'name' => 'required', 'type' => 'in:' . $form->el('type')->listValues(), ]; $resolver = new \Okneloper\Forms\Validation\Illuminate\IlluminateValidatorResolver($app, $rules); $form->setValidatorResolver($resolver); $form->submit($_POST); if ($form->isValid()) { var_dump($form->getModel()); // the model now contains filtered and validated POST values } else { $errors = $form->getValidator()->getErrorMessages(); } }
Elements
Buttons
$form->add('button', 'btn', 'ClickMe'); // <buttont type="button"...>ClickMe</button> $form->add('submitButton', 'btn', 'Submit'); // <buttont type="submit">Submit</button>
Button values are ignored when submitting request data to the form.
<?php $form = new \Okneloper\Forms\Form(); $form->add('text', 'fname'); $form->add('text', 'lname'); $form->add('submitButton', 'Submit'); // this is how data might come from a submitted form $data = [ 'fname' => 'John', 'lname' => 'Smith', 'Submit' => '1', ]; $form->submit($data); print_r($form->modelToArray()); ?> Array ( [fname] => John [lname] => Smith )