| 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 |
|