Ejemplo n.º 1
0
{
    public $name;
    public $actors;
}
include __DIR__ . '/../autoload.php';
$form = new Gregwar\Formidable\Form('<form method="post">

    <h2>Film</h2>
    Film name:
    <input type="text" name="film_name" mapping="name" />
    <hr />

    <h2>Actors</h2>
    <multiple name="actors" mapping="actors" min-entries="2">
        <fieldset>
            First name: <input name="first_name" mapping="firstName" /><br />
            Last name: <input name="last_name" mapping="lastName" /><br />
            Age: <input type="int" name="age" min="7" mapping="age" optional />
            Gender:
            <select mapping="gender" name="gender">
                <option value="m">Male</option>
                <option value="f">Female</option>
            </select>
        </fieldset>
    </multiple>
    <input type="submit" />
    </form>', array(), true);
$form->handle(function () use($form) {
    var_dump($form->getData(new Film()));
}, function ($errors) {
    echo "Errors:<br />";
    foreach ($errors as $error) {
Ejemplo n.º 2
0
<?php

include __DIR__ . '/../autoload.php';
$form = new Gregwar\Formidable\Form('<form method="post">
    <custom source="something" />
    </form>');
$form->source('something', 'Hello world!');
echo $form;
Ejemplo n.º 3
0
<?php

include __DIR__ . '/../autoload.php';
$form = new Gregwar\Formidable\Form('<form method="post">
    <select name="animal">
        <options source="animals" />
    </select>
    </form>');
$form->source('animals', array('cat' => 'Cat', 'dog' => 'Dog'));
$form->setValue('animal', 'dog');
echo $form;
Ejemplo n.º 4
0
<?php

$_SESSION = array();
include __DIR__ . '/../autoload.php';
$form = new Gregwar\Formidable\Form('<form method="post">
    What\'s your name? <input type="text" name="nom" /><br />
    <input type="submit" />
    </form>', null, true);
$form->setValue('nom', 'Jack');
echo $form;
Ejemplo n.º 5
0
<?php

session_start();
// required for CSRF
include __DIR__ . '/../autoload.php';
include 'person.php';
$form = new Gregwar\Formidable\Form('forms/demoform.html', array());
// Example for setting language to french
// $form->setLanguage(new Gregwar\Formidable\Language\French);
$form->addConstraint('firstname', function ($value) {
    if ($value[0] == 'P') {
        return 'The firstname should not begin with a P!';
    }
});
$form->source('animals', array('zebra' => 'Zebra', 'bonobo' => 'Bonobo'));
$errors = $form->handle(function () use($form) {
    $data = $form->getValues();
    var_dump($data);
});
?>
<!DOCTYPE html>
<html>
    <meta charset="utf-8" />
    <head>
        <title>Formidable Demo</title>
    </head> 
    <body>
        <h1>Formidable Demo</h1>
        <?php 
if ($errors) {
    ?>
Ejemplo n.º 6
0
<?php

include __DIR__ . '/../autoload.php';
class Person
{
    protected $name;
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
}
$person = new Person();
$person->setName('Jack');
$form = new Gregwar\Formidable\Form('<form method="post">
    <input type="text" name="name" mapping="name" />
    </form>');
$form->setData($person);
echo $form;
/*
Will output something like:

<form method="post">
    <input required="required" type="text" name="name" value="Jack" />
    <input type="hidden" name="csrf_token" value="aa27f437cc6127c244db14361fd614af51c79aac" />
</form>
*/
Ejemplo n.º 7
0
<?php

include __DIR__ . '/../autoload.php';
$form = new Gregwar\Formidable\Form('<form method="post">
    <select name="colour">
        <option value="blue">Blue</option>
        <option selected value="red">Red</option>
        <option value="green">Green</option>
    </select>
    </form>');
echo $form->getValue('colour') . "\n";
// red
// Sets the color to blue
$form->setValue('colour', 'blue');
echo $form;
/* Will display:
<form method="post">
    <select name="colour" >
        <option selected="selected" value="blue">Blue</option>
        <option value="red">Red</option>
        <option value="green">Green</option>
    </select>
    <input type="hidden" name="csrf_token" value="d293dc38017381b6086ff1a856c1e8fe43738c60" />
</form>
*/
Ejemplo n.º 8
0
<?php

include __DIR__ . '/../autoload.php';
$form = new Gregwar\Formidable\Form('<form method="post">
    <span style="color:{{ color }}">Hello</span>
    </form>');
$form->setPlaceholder('color', 'red');
echo $form;