PHPackages                             okneloper/forms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. okneloper/forms

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

okneloper/forms
===============

Build, control, submit and validate forms, hassle free.

v0.10.5(7y ago)2761MITPHPPHP &gt;=5.5.0

Since Jan 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/okneloper/forms)[ Packagist](https://packagist.org/packages/okneloper/forms)[ Docs](https://github.com/okneloper/forms)[ RSS](/packages/okneloper-forms/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (40)Used By (0)

Build, control, submit and validate forms.
==========================================

[](#build-control-submit-and-validate-forms)

- 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
------------------------------------------------------------------

[](#a-very-simple-example-of-a-using-a-form-with-illuminatevalidation)

```
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
--------

[](#elements)

### Buttons

[](#buttons)

```
$form->add('button', 'btn', 'ClickMe'); // ClickMe
$form->add('submitButton', 'btn', 'Submit'); // Submit
```

Button values are ignored when submitting request data to the form.

```
