Created
September 27, 2021 11:51
-
-
Save dg/370a7e3094d9ba9a9e913b8e2a2dc851 to your computer and use it in GitHub Desktop.
Standalone Nette Forms example [en]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
if (@!include __DIR__ . '/../vendor/autoload.php') { | |
die('Install packages using `composer require nette/forms`'); | |
} | |
use Nette\Forms\Form; | |
$form = new Form; | |
$form->addText('name', 'Name:') | |
->setRequired(); | |
$form->addPassword('password', 'Password:') | |
->setRequired(); | |
$form->addSubmit('send', 'Register'); | |
if ($form->isSuccess()) { | |
echo 'The form has been correctly completed and submitted'; | |
$data = $form->getValues(); | |
var_dump($data); | |
// $data->name contains the name | |
// $data->password contains the password | |
// process the data and redirect to another page | |
} | |
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