Skip to content

Instantly share code, notes, and snippets.

@dg
Created September 27, 2021 11:51
Show Gist options
  • Save dg/57878c1a413ae8ef0c1d83f02c43ef3f to your computer and use it in GitHub Desktop.
Save dg/57878c1a413ae8ef0c1d83f02c43ef3f to your computer and use it in GitHub Desktop.
Standalone Nette Forms example [cs]
<?php
declare(strict_types=1);
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Nainstalujte balíčky pomocí `composer require nette/forms`');
}
use Nette\Forms\Form;
$form = new Form;
$form->addText('name', 'Jméno:')
->setRequired();
$form->addPassword('password', 'Heslo:')
->setRequired();
$form->addSubmit('send', 'Registrovat');
if ($form->isSuccess()) {
echo 'Formulář byl správně vyplněn a odeslán';
$data = $form->getValues();
var_dump($data);
// $data->name obsahuje jméno
// $data->password obsahuje heslo
// zpracujeme data a přesměrujeme na jinou stránku
}
echo '
<!doctype html>
<meta charset="utf-8">
<script src="https://nette.github.io/resources/js/3/netteForms.js"></script>
';
$form->render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment