コード例 #1
0
ファイル: multiple.php プロジェクト: rgv151/Formidable
$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) {
        echo "* {$error}<br/>";
    }
});
echo $form;
コード例 #2
0
ファイル: index.php プロジェクト: rgv151/Formidable
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) {
    ?>
            <div style="color:red">
                <h2>Validations error</h1>