| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Nette Forms and HTML5. |
| 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->addGroup(); |
| 18 |
$form->addText('query', 'Search:')->setHtmlType('search')->setHtmlAttribute('autofocus'); |
| 19 |
$form->addText('count', 'Number of results:')->setHtmlType('number')->setDefaultValue(10)->addRule($form::INTEGER, 'Must be numeric value')->addRule($form::RANGE, 'Must be in range from %d to %d', [1, 100]); |
| 20 |
$form->addText('precision', 'Precision:')->setHtmlType('range')->setDefaultValue(50)->addRule($form::INTEGER, 'Precision must be numeric value')->addRule($form::RANGE, 'Precision must be in range from %d to %d', [0, 100]); |
| 21 |
$form->addEmail('email', 'Send to email:')->setHtmlAttribute('autocomplete', 'off')->setHtmlAttribute('placeholder', 'Optional, but Recommended'); |
| 22 |
$form->addSubmit('submit', 'Send'); |
| 23 |
if ($form->isSuccess()) { |
| 24 |
echo '<h2>Form was submitted and successfully validated</h2>'; |
| 25 |
Dumper::dump($form->getValues()); |
| 26 |
exit; |
| 27 |
} |
| 28 |
?> |
| 29 |
<!DOCTYPE html> |
| 30 |
<meta charset="utf-8"> |
| 31 |
<title>Nette Forms and HTML5</title> |
| 32 |
<link rel="stylesheet" media="screen" href="assets/style.css" /> |
| 33 |
<script src="https://nette.github.io/resources/js/3/netteForms.js"></script> |
| 34 |
|
| 35 |
<h1>Nette Forms and HTML5</h1> |
| 36 |
|
| 37 |
<?php |
| 38 |
$form->render(); |
| 39 |
?> |
| 40 |
|
| 41 |
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer> |
| 42 |
<?php |
| 43 |
|