Input generation library for value resolution, data persistence, templates, CSRF and protection from XSS., (*2)
Documentation
This document serves as Dora API documentation. If you prefer, you can learn Dora API while browsing the interactive demonstration and use this document for the API reference., (*3)
Form
Form is a data container., (*4)
/**
* @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., (*5)
echo $form->input('foo');
Input with name "foo" will inherit "Heeeere's...Johnny!" value:, (*6)
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., (*9)
Input is a standalone entity defined with four parameters. Only the first parameter is required., (*10)
/**
* @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)., (*11)
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 <select>, "textarea" will make it <textarea>., (*12)
Input Properties
Input properties are used at the time of generating the input template., (*13)
Name
Description
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 <select> input type. Passing this property will assume that input type is "select".
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:, (*14)
$form = new \Gajus\Dora\Form([], 'Gajus\Dora\Template\Traditional');
"Gajus\Dora\Template\Traditional" is the default template. null will return input without template., (*15)
Traditional Template
Traditional template consists of label, input and optional description., (*16)
##### Styling
Dora or the Traditional template does not impose style. The [example of styling the Tranditional layout](http://jsfiddle.net/vac2E/1/) is for illustration purposes only.

#### Writing a Template
Template class must extend `Gajus\Dora\Template`.
Refer to the existing templates to learn more.
### CSRF
Form generated using Dora need to be signed:
```php
$form = new \Gajus\Dora\Form();
?>
<form>
<?=$form->sign()?>
<input type="submit">
</form>
The generated signature consists of UID and CSRF tokes:, (*19)
Dora assumes that application is designed using Post/Redirect/Get pattern. Dora will not populate form upon POST request because it is assumed that POST request will result in a redirect. Dora will copy POST data and store it in a temporary session. This is achieved using ./src/inc/agent.php script. If you are using composer, then this script is automatically included in every request., (*25)
Data Persistence
Using the Post/Redirect/Get pattern requires special handling of user input. If you want to return user to the form after POST event (e.g. in case of an error), you do not want to make user re-enter all the values all over again. Dora utilises $_SESSION['gajus']['dora']['flash'] variable to copy $_POST data for one Post/Redirect/Get cycle. If you return user to the form after POST, form will be populated with the originally submitted data., (*26)
Installation
The recommended way to use Dora is through Composer., (*27)