PluginProbe
Packeta / trunk
Packeta vtrunk
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / deps / nette / forms / examples / latte.php

latte.php in Packeta trunk, at deps/nette/forms/examples/latte.php

31 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Nette Forms rendering using Latte.
5 */
6 declare (strict_types=1);
7 namespace Packetery;
8
9 if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
10 die('Install packages using `composer install`');
11 }
12 use Packetery\Nette\Forms\Form;
13 use Packetery\Tracy\Debugger;
14 use Packetery\Tracy\Dumper;
15 Debugger::enable();
16 $form = new Form();
17 $form->addText('name', 'Your name:')->setRequired('Enter your name');
18 $form->addPassword('password', 'Choose password:')->setRequired('Choose your password')->addRule($form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
19 $form->addPassword('password2', 'Reenter password:')->setRequired('Reenter your password')->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
20 $form->addSubmit('submit', 'Send');
21 if ($form->isSuccess()) {
22 echo '<h2>Form was submitted and successfully validated</h2>';
23 Dumper::dump($form->getValues());
24 exit;
25 }
26 $latte = new Latte\Engine();
27 $latte->onCompile[] = function ($latte) {
28 \Packetery\Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
29 };
30 $latte->render('template.latte', ['form' => $form]);
31