PHPackages                             gajus/dora - 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. [Security](/categories/security)
4. /
5. gajus/dora

ActiveLibrary[Security](/categories/security)

gajus/dora
==========

Input generation library for value resolution, data persistence, templates, CSRF and protection from XSS.

0.1.5(12y ago)72376[3 issues](https://github.com/gajus/dora/issues)BSD-3-ClauseCSSPHP &gt;=5.4

Since Apr 9Pushed 11y ago6 watchersCompare

[ Source](https://github.com/gajus/dora)[ Packagist](https://packagist.org/packages/gajus/dora)[ Docs](https://github.com/gajus/dora)[ RSS](/packages/gajus-dora/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

Dora
====

[](#dora)

[![Build Status](https://camo.githubusercontent.com/7f7fdd55bf9388a3f2c57bb6f145f07c52c43c1330d1641f8be0512d1cd97754/68747470733a2f2f7472617669732d63692e6f72672f67616a75732f646f72612e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/gajus/dora)[![Coverage Status](https://camo.githubusercontent.com/04fe10bde40bdf9a7393065579a9a336fe1702bc85b3a8f5da411ca334842b8b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f67616a75732f646f72612f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/gajus/dora?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/a0e7b724295cf569a425dfea84cdc811d9d8ea1cd3e7dbef193ce288c8e368f9/68747470733a2f2f706f7365722e707567782e6f72672f67616a75732f646f72612f76657273696f6e2e706e67)](https://packagist.org/packages/gajus/dora)[![License](https://camo.githubusercontent.com/9f9ff2d184861f350b52c2383893ee37cb5c3d30a1315445296e9e7762245525/68747470733a2f2f706f7365722e707567782e6f72672f67616a75732f646f72612f6c6963656e73652e706e67)](https://packagist.org/packages/gajus/dora)

Input generation library for value resolution, data persistence, templates, CSRF and protection from XSS.

Documentation
-------------

[](#documentation)

This document serves as Dora API documentation. If you prefer, you can learn Dora API while browsing the [interactive demonstration](http://gajus.com/sandbox/dora/demo/) and use this document for the API reference.

### Form

[](#form)

`Form` is a data container.

```
/**
 * @param array $data Data used to populate Input generated using an instance of this Form.
 * @param null|string $template Template class name.
 */
$form = new \Gajus\Dora\Form([
    'foo' => 'Heeeere\'s...Johnny!',
    'bar' => 'Yada, yada, yada.',
    'baz' => 0,
    'qux' => ['1', 2 => '3'],
    'corge[grault]' = 'garply'
], null);
```

`Input` generated using an instance of the `Form` will inherit `Form` data.

```
echo $form->input('foo');
```

`Input` with name "foo" will inherit "Heeeere's...Johnny!" value:

```

```

`Input` can be any type of HTML input.

```
echo $form->input('bar', ['type' => 'textarea', 'class' => 'test']);
echo $form->input('baz', null, ['options' => ['Knock, knock...', 'Come in.']]);
```

```
Yada, yada, yada.

    Knock, knock...
    Come in.

```

`Input` name can resolve value from an array:

```
echo $form->input('corge[grault]');
```

When `Input` is declared using variable array syntax, `Input` index (ie., order in which `Input` is generated) will be matched against the value with the respective index in the data array.

```
echo $form->input('qux[]');
echo $form->input('qux[]');
echo $form->input('qux[]');
```

```

```

### Input

[](#input)

Input is a standalone entity defined with four parameters. Only the first parameter is required.

```
/**
 * @param string $name Input name.
 * @param array $attributes HTML attributes.
 * @param array $properties Input properties, e.g. input name.
 * @param null|string $template Template class name.
 */
new \Gajus\Dora\Input('foo', ['type' => 'textarea'], ['name' => 'Foo'], null);
```

Most of the time, `Form` will act as a factory to produce `Input` (like in all the examples on this page).

#### HTML attributes

[](#html-attributes)

HTML attributes that are added to the generated input. All attributes will be taken literally except "type". "type" attribute will change the actual input type, e.g. "select" will make input ``, "textarea" will make it ``.

#### Input Properties

[](#input-properties)

Input properties are used at the time of generating the input template.

NameDescription`name`Name is not a required property. Input `name` property is used when input is used in template, e.g. for the label. If input `name` property is not provided, English name will be derived from the "name" attribute, e.g. `foo[bar_tar_id]` will come out as "Foo Bar Tar".`options``options` property is not required. This proprety is for `` input type. Passing this property will assume that input type is "select".### Template

[](#template)

`Input` can be dressed using a `Template`. `Template` is utilsed when input is casted into a string. `Form` template will become the default template for all the `Input` generated using an instance of that `Form`:

```
$form = new \Gajus\Dora\Form([], 'Gajus\Dora\Template\Traditional');
```

"Gajus\\Dora\\Template\\Traditional" is the default template. `null` will return input without template.

#### Traditional Template

[](#traditional-template)

Traditional template consists of label, input and optional description.

```
