1. Go to this page and download the library: Download tuum/form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tuum / form example snippets
$view = new Tuum\Form\DataView();
$view->setData([
'name' => 'my-name',
'bold' => '<b>bold</b>',
'list' => ['v1', 'v2'],
]);
$view->setInputs([
'name' => 'old-name',
'more' => [
'key' => 'val'
]
]);
// getting escaped data.
echo $view->data['name']; // 'my-name'
echo $view->data['bold']; // escaped <b>bold</b>
echo $view->data->get('bold'); // escaped <b>bold</b>
echo $view->data->raw('bold'); // raw <b>bold</b>
// and arrays.
$list = $view->data->extractKey('list');
echo $list[0]; // 'v1'
echo $list[1]; // 'v2'
// getting old inputs
echo $view->inputs->get('name', $data['name']); // 'old-name'
echo $view->inputs->get('more[key]'); // val
// and use it in form generator.
echo $view->forms->text('name', 'default');
// will output <input type="text" value="old-name">
$esc = new Escape();
echo $esc('<danger>safe</danger>'); // or
echo $esc->escape('<danger>safe</danger>');
$esc = new Escape('addslashes');
// or
$esc = $esc->setEscape('rawurlencode');
$view = new DataView(new Escape('addslashes'));
$view->inputs->get('with-slash'); // escaped with addslashes.
// or change how to escape
$view->escape->setEscape('rawurlencode');
// construct yourself.
$data = Data::forge(['view'=>'<i>val</i>'], $escape);
// or use DataView class.
$view = new DataView();
$view->setData(['some'=>'value']);
$data = $view->data;
echo $data['view']; // escaped
echo $data->view; // escaped
echo $data->get('view'); // escaped
echo $data->raw('view'); // raw value
echo $data->get('none', 'non\'s'); // show escaped default value