Esempio n. 1
0
 public function testForm()
 {
     $form = new \Gajus\Dora\Form([], null);
     $input = $form->input('foo');
     $input = '' . $input;
     $this->assertSame('<input name="foo" type="text" value="">', $input);
 }
Esempio n. 2
0
 public function testForm()
 {
     $form = new \Gajus\Dora\Form([], 'Gajus\\Dora\\Template\\Test');
     $input = $form->input('foo');
     $input = '' . $input;
     $this->assertSame('test', $input);
 }
Esempio n. 3
0
 public function testFormSigning()
 {
     $uid = (string) crc32(__FILE__ . '_' . (__LINE__ + 3));
     $csrf = sha1(session_id());
     $form = new \Gajus\Dora\Form();
     $this->assertSame($form->getUid(), $uid);
     $this->assertSame(preg_replace('/[^a-b]/', '', '<input type="hidden" name="gajus[dora][uid]" value="' . $uid . '"><input type="hidden" name="gajus[dora][csrf]" value="' . $csrf . '">'), preg_replace('/[^a-b]/', '', $form->sign()));
 }
Esempio n. 4
0
 public function testInputData()
 {
     $uid = (string) crc32(__FILE__ . '_' . (__LINE__ + 11));
     $input = ['foo' => 'bar', 'gajus' => ['dora' => ['uid' => $uid]]];
     $form = new \Gajus\Dora\Form($input);
     $this->assertSame($form->getUid(), $uid);
     $this->assertTrue($form->isSubmitted(false));
     $this->assertSame(['foo' => 'bar'], $form->getData());
 }
Esempio n. 5
0
 public function testIsSubmittedInputWithCSRFCheck()
 {
     $uid = (string) crc32(__FILE__ . '_' . (__LINE__ + 6));
     $csrf = sha1(session_id());
     $input['gajus']['dora']['uid'] = $uid;
     $input['gajus']['dora']['csrf'] = $csrf;
     $form = new \Gajus\Dora\Form($input);
     $this->assertSame($form->getUid(), $uid);
     $this->assertTrue($form->isSubmitted(false));
     $this->assertTrue($form->isSubmitted());
 }
Esempio n. 6
0
 public function testDefault()
 {
     $form = new \Gajus\Dora\Form([], 'Gajus\\Dora\\Template\\Traditional');
     $input = $form->input('foo', ['id' => 'test']);
     $input = $input->toString();
     // https://gist.github.com/anonymous/220b2cec6d51ea5bc728
     $this->assertSame(preg_replace('/[^a-z]/', '', '
         <div class="dora-input">
             <label for="test">Foo</label>
             <input id="test" name="foo" type="text" value="">
         </div>
         '), preg_replace('/[^a-z]/', '', $input));
 }
Esempio n. 7
0
<?php

$form = new \Gajus\Dora\Form();
$label = new \Gajus\Dora\Label($form, function ($input) {
    // Retrieve all entries for "tag-list". Inbox is input specific.
    // $tags = $input->getInbox('tag-list');
    ob_start();
    ?>
    <div class="dora-input">
        <label for="<?php 
    echo $input->getAttribute('id');
    ?>
"><?php 
    echo $input->getProperty('label');
    ?>
</label>
        <?php 
    echo $input;
    ?>
        <?php 
    /*if ($tags):?>
      <ul class="demo-tags">
          <li><?=implode('</li><li>', $tags)?></li>
      </ul>
      <?php endif;*/
    ?>
    </div>
    <?php 
    return ob_get_clean();
});
?>
Esempio n. 8
0
<?php

// Custom template must extend Gajus\Dora\Template
class MyTemplate extends \Gajus\Dora\Template
{
    public function toString()
    {
        $input = $this->getInput();
        ob_start();
        ?>
        <div class="dora-input custom">
            <label for="<?php 
        echo $input->getAttribute('id');
        ?>
"><?php 
        echo $input->getProperty('name');
        ?>
</label>
            <?php 
        echo $input;
        ?>
        </div>
        <?php 
        return ob_get_clean();
    }
}
$form = new \Gajus\Dora\Form(null, 'MyTemplate');
echo $form->input('baz', null, ['name' => 'Baz Custom Name']);
echo $form->input('qux', null, ['name' => 'Qux Custom Name']);
// You can change individual input template too.
echo $form->input('qux', null, ['name' => 'Qux Custom Name'], 'Gajus\\Dora\\Template\\Traditional');
Esempio n. 9
0
<?php

$form = new \Gajus\Dora\Form($_POST);
// Note that "bar" input has a default value:
// $form->input('bar', ['value' => mt_rand(1000,9999)])
// However, when you submit the form, this value is overwritten.
// Form signature is used to generate UID and CSRF tokens.
// UID is used to identify instance of the form that's submitted.
// Form signature is generated using $form->sign().
if ($form->isSubmitted()) {
    header('Location: ' . $_SERVER['REQUEST_URI']);
    exit;
}
?>
<form action="" method="post">
    <?php 
echo $form->input('foo');
?>
    <?php 
echo $form->input('bar', ['value' => mt_rand(1000, 9999)]);
?>
    
    <div class="button-group">
        <?php 
echo $form->input('action[submit]', ['type' => 'submit', 'value' => 'Submit'], null, null);
?>
    </div>

    <?php 
echo $form->sign();
?>
Esempio n. 10
0
<?php

// This example demonstrates how to generate basic input.
// Values passed the Form constructor are mapped to the generated Input.
// This example is using the default input template.
// Therefore, input comes wraped in <div class="dora-input"></div> container
// with dynamically generated input name property.
/**
 * @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]);
/**
 * Create Input associated with the Form instance data.
 * 
 * @param string $name
 * @param array $attributes
 * @param array $properties
 * @param string $template
 * @return \Gajus\Dora\Input
 */
echo $form->input('foo');
echo $form->input('bar', ['type' => 'textarea', 'class' => 'test']);
echo $form->input('baz', null, ['options' => ['Knock, knock...', 'Come in.']]);
Esempio n. 11
0
<?php

$form = new \Gajus\Dora\Form();
// Attibutes are defined using the second Input parameter.
echo $form->input('foo', ['data-foo' => 'bar']);
// If Input "id" attribute is not defined, and it is requested before Input is stringified,
// then a new random (semi-persistent) ID will be generated.
$input = $form->input('foo');
?>
<dl>
    <dt>Id</dt>
    <dd><?php 
echo $input->getAttribute('id');
?>
</dd>
</dl>
Esempio n. 12
0
<?php

$form = new \Gajus\Dora\Form(['mu' => ['lt' => ['id' => ['im' => ['en' => ['si' => ['on' => ['al' => 'Multidimensional Data']]]]]]], 'array' => ['', 'second'], 'checkbox_multiple' => ['c', 'd'], 'radio' => 'b']);
// Multidimensional data
echo $form->input('mu[lt][id][im][en][si][on][al]');
// Array data
echo $form->input('array[]');
echo $form->input('array[]');
echo $form->input('array[]');
// Passing "options" parameter implies that the input type is "select".
echo $form->input('select_multiple[]', ['multiple' => 'multiple'], ['options' => ['Quick!', 'To the Batmobile!', 'Da-na-na-na', 'Na-na-na-na']]);
echo $form->input('checkbox_multiple[]', ['type' => 'checkbox', 'value' => 'a']);
echo $form->input('checkbox_multiple[]', ['type' => 'checkbox', 'value' => 'b']);
echo $form->input('checkbox_multiple[]', ['type' => 'checkbox', 'value' => 'c']);
echo $form->input('checkbox_multiple[]', ['type' => 'checkbox', 'value' => 'd']);
echo $form->input('radio', ['type' => 'radio', 'value' => 'a']);
echo $form->input('radio', ['type' => 'radio', 'value' => 'b']);
Esempio n. 13
0
<?php

$form = new \Gajus\Dora\Form([], null);
// "input" method returns an instance of Gajus\Dora\Input.
// Use "name" property to give Input a human-readable name.
$input = $form->input('foo', null, ['name' => 'Foo Label Property']);
?>
<div class="dora-input">
    <label><?php 
echo $input->getProperty('name');
?>
</label>
    <?php 
echo $input;
?>
</div>
<?php 
// When "name" property is not provided, Dora will derive name from the input "name" attribute.
$input = $form->input('bar[baz_qux][]');
?>
<dl>
    <dt>bar[baz_qux][]</dt>
    <dd><?php 
echo $input->getProperty('name');
?>
</dd>
</dl>