no message
This commit is contained in:
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
+72
@@ -0,0 +1,72 @@
|
||||
/** common style for Nette examples */
|
||||
|
||||
html {
|
||||
font: 16px/1.5 sans-serif;
|
||||
border-top: 4.7em solid #F4EBDB;
|
||||
}
|
||||
|
||||
body {
|
||||
max-width: 990px;
|
||||
margin: -4.7em auto 0;
|
||||
background: white;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.9em;
|
||||
margin: .5em 0 1.5em;
|
||||
background: url(logo.png) right center no-repeat;
|
||||
color: #7A7772;
|
||||
text-shadow: 1px 1px 0 white;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
padding: .2em 1em 1em;
|
||||
margin: .5em 0;
|
||||
background: #E4F1FC;
|
||||
border: 1px solid #B2D1EB;
|
||||
}
|
||||
|
||||
textarea,
|
||||
select,
|
||||
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="image"]):not([type="range"]) {
|
||||
padding: .3em .5em;
|
||||
color: black;
|
||||
background: white;
|
||||
border: 1px solid silver;
|
||||
}
|
||||
|
||||
.has-error textarea,
|
||||
.has-error select,
|
||||
.has-error input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="image"]):not([type="range"]) {
|
||||
border-color: #E22;
|
||||
}
|
||||
|
||||
select {
|
||||
padding-right: .3em;
|
||||
}
|
||||
|
||||
input[type="submit"] {
|
||||
font-size: 120%;
|
||||
}
|
||||
|
||||
th {
|
||||
width: 10em;
|
||||
text-align: right;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.required label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #E22;
|
||||
font-weight: bold;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
footer a {
|
||||
font-size: 70%;
|
||||
color: gray;
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms basic example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Nette\Utils\Html;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
$form = new Form;
|
||||
|
||||
// group Personal data
|
||||
$form->addGroup('Personal data')
|
||||
->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.');
|
||||
|
||||
$form->addText('name', 'Your name:')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addText('age', 'Your age:')
|
||||
->setRequired('Enter your age')
|
||||
->addRule($form::INTEGER, 'Age must be numeric value')
|
||||
->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);
|
||||
|
||||
$form->addRadioList('gender', 'Your gender:', [
|
||||
'm' => 'male',
|
||||
'f' => 'female',
|
||||
]);
|
||||
|
||||
$form->addCheckboxList('colors', 'Favorite colors:', [
|
||||
'r' => 'red',
|
||||
'g' => 'green',
|
||||
'b' => 'blue',
|
||||
]);
|
||||
|
||||
$form->addEmail('email', 'Email:')
|
||||
->setEmptyValue('@');
|
||||
|
||||
|
||||
// group Shipping address
|
||||
$form->addGroup('Shipping address')
|
||||
->setOption('embedNext', true);
|
||||
|
||||
$form->addCheckbox('send', 'Ship to address')
|
||||
->addCondition($form::FILLED) // conditional rule: if is checkbox checked...
|
||||
->toggle('sendBox'); // toggle div #sendBox
|
||||
|
||||
|
||||
// subgroup
|
||||
$form->addGroup()
|
||||
->setOption('container', Html::el('div')->id('sendBox'));
|
||||
|
||||
$form->addText('street', 'Street:');
|
||||
|
||||
$form->addText('city', 'City:')
|
||||
->addConditionOn($form['send'], $form::FILLED)
|
||||
->setRequired('Enter your shipping address');
|
||||
|
||||
$countries = [
|
||||
'World' => [
|
||||
'bu' => 'Buranda',
|
||||
'qu' => 'Qumran',
|
||||
'st' => 'Saint Georges Island',
|
||||
],
|
||||
'?' => 'other',
|
||||
];
|
||||
$form->addSelect('country', 'Country:', $countries)
|
||||
->setPrompt('Select your country')
|
||||
->addConditionOn($form['send'], $form::FILLED)
|
||||
->setRequired('Select your country');
|
||||
|
||||
|
||||
// group Your account
|
||||
$form->addGroup('Your account');
|
||||
|
||||
$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);
|
||||
|
||||
$form->addPassword('password2', 'Reenter password:')
|
||||
->setRequired('Reenter your password')
|
||||
->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
|
||||
|
||||
$form->addUpload('avatar', 'Picture:')
|
||||
->setRequired(false)
|
||||
->addRule($form::IMAGE, 'Uploaded file is not image');
|
||||
|
||||
$form->addHidden('userid');
|
||||
|
||||
$form->addTextArea('note', 'Comment:');
|
||||
|
||||
// group for buttons
|
||||
$form->addGroup();
|
||||
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
$form->setDefaults([
|
||||
'name' => 'John Doe',
|
||||
'userid' => 231,
|
||||
]);
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues(), [Dumper::COLLAPSE => false]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms basic example</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
|
||||
<h1>Nette Forms basic example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms & Bootstap v2 rendering example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
function makeBootstrap2(Form $form)
|
||||
{
|
||||
$renderer = $form->getRenderer();
|
||||
$renderer->wrappers['controls']['container'] = null;
|
||||
$renderer->wrappers['pair']['container'] = 'div class=control-group';
|
||||
$renderer->wrappers['pair']['.error'] = 'error';
|
||||
$renderer->wrappers['control']['container'] = 'div class=controls';
|
||||
$renderer->wrappers['label']['container'] = 'div class=control-label';
|
||||
$renderer->wrappers['control']['description'] = 'span class=help-inline';
|
||||
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-inline';
|
||||
$form->getElementPrototype()->class('form-horizontal');
|
||||
|
||||
foreach ($form->getControls() as $control) {
|
||||
$type = $control->getOption('type');
|
||||
if ($type === 'button') {
|
||||
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn');
|
||||
$usedPrimary = true;
|
||||
|
||||
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
|
||||
$control->getSeparatorPrototype()->setName('div')->addClass($type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form = new Form;
|
||||
$form->onRender[] = 'makeBootstrap2';
|
||||
|
||||
$form->addGroup('Personal data');
|
||||
$form->addText('name', 'Your name')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addRadioList('gender', 'Your gender', [
|
||||
'male', 'female',
|
||||
]);
|
||||
|
||||
$form->addCheckboxList('colors', 'Favorite colors', [
|
||||
'red', 'green', 'blue',
|
||||
]);
|
||||
|
||||
$form->addSelect('country', 'Country', [
|
||||
'Buranda', 'Qumran', 'Saint Georges Island',
|
||||
]);
|
||||
|
||||
$form->addCheckbox('send', 'Ship to address');
|
||||
|
||||
$form->addGroup('Your account');
|
||||
$form->addPassword('password', 'Choose password');
|
||||
$form->addUpload('avatar', 'Picture');
|
||||
$form->addTextArea('note', 'Comment');
|
||||
|
||||
$form->addGroup();
|
||||
$form->addSubmit('submit', 'Send');
|
||||
$form->addSubmit('cancel', 'Cancel');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms & Bootstrap v2 rendering example</title>
|
||||
|
||||
<link rel="stylesheet" media="screen" href="https://netdna.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css" />
|
||||
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>Nette Forms & Bootstrap v2 rendering example</h1>
|
||||
</div>
|
||||
|
||||
<?php echo $form ?>
|
||||
</div>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms & Bootstap v3 rendering example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
function makeBootstrap3(Form $form)
|
||||
{
|
||||
$renderer = $form->getRenderer();
|
||||
$renderer->wrappers['controls']['container'] = null;
|
||||
$renderer->wrappers['pair']['container'] = 'div class=form-group';
|
||||
$renderer->wrappers['pair']['.error'] = 'has-error';
|
||||
$renderer->wrappers['control']['container'] = 'div class=col-sm-9';
|
||||
$renderer->wrappers['label']['container'] = 'div class="col-sm-3 control-label"';
|
||||
$renderer->wrappers['control']['description'] = 'span class=help-block';
|
||||
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
|
||||
$form->getElementPrototype()->class('form-horizontal');
|
||||
|
||||
foreach ($form->getControls() as $control) {
|
||||
$type = $control->getOption('type');
|
||||
if ($type === 'button') {
|
||||
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
|
||||
$usedPrimary = true;
|
||||
|
||||
} elseif (in_array($type, ['text', 'textarea', 'select'], true)) {
|
||||
$control->getControlPrototype()->addClass('form-control');
|
||||
|
||||
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
|
||||
$control->getSeparatorPrototype()->setName('div')->addClass($type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form = new Form;
|
||||
$form->onRender[] = 'makeBootstrap3';
|
||||
|
||||
$form->addGroup('Personal data');
|
||||
$form->addText('name', 'Your name')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addRadioList('gender', 'Your gender', [
|
||||
'male', 'female',
|
||||
]);
|
||||
|
||||
$form->addCheckboxList('colors', 'Favorite colors', [
|
||||
'red', 'green', 'blue',
|
||||
]);
|
||||
|
||||
$form->addSelect('country', 'Country', [
|
||||
'Buranda', 'Qumran', 'Saint Georges Island',
|
||||
]);
|
||||
|
||||
$form->addCheckbox('send', 'Ship to address');
|
||||
|
||||
$form->addGroup('Your account');
|
||||
$form->addPassword('password', 'Choose password');
|
||||
$form->addUpload('avatar', 'Picture');
|
||||
$form->addTextArea('note', 'Comment');
|
||||
|
||||
$form->addGroup();
|
||||
$form->addSubmit('submit', 'Send');
|
||||
$form->addSubmit('cancel', 'Cancel');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms & Bootstrap v3 rendering example</title>
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
|
||||
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>Nette Forms & Bootstrap v3 rendering example</h1>
|
||||
</div>
|
||||
|
||||
<?php echo $form ?>
|
||||
</div>
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms & Bootstap v4 rendering example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
function makeBootstrap4(Form $form)
|
||||
{
|
||||
$renderer = $form->getRenderer();
|
||||
$renderer->wrappers['controls']['container'] = null;
|
||||
$renderer->wrappers['pair']['container'] = 'div class="form-group row"';
|
||||
$renderer->wrappers['pair']['.error'] = 'has-danger';
|
||||
$renderer->wrappers['control']['container'] = 'div class=col-sm-9';
|
||||
$renderer->wrappers['label']['container'] = 'div class="col-sm-3 col-form-label"';
|
||||
$renderer->wrappers['control']['description'] = 'span class=form-text';
|
||||
$renderer->wrappers['control']['errorcontainer'] = 'span class=form-control-feedback';
|
||||
|
||||
foreach ($form->getControls() as $control) {
|
||||
$type = $control->getOption('type');
|
||||
if ($type === 'button') {
|
||||
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-secondary');
|
||||
$usedPrimary = true;
|
||||
|
||||
} elseif (in_array($type, ['text', 'textarea', 'select'], true)) {
|
||||
$control->getControlPrototype()->addClass('form-control');
|
||||
|
||||
} elseif ($type === 'file') {
|
||||
$control->getControlPrototype()->addClass('form-control-file');
|
||||
|
||||
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
|
||||
if ($control instanceof Nette\Forms\Controls\Checkbox) {
|
||||
$control->getLabelPrototype()->addClass('form-check-label');
|
||||
} else {
|
||||
$control->getItemLabelPrototype()->addClass('form-check-label');
|
||||
}
|
||||
$control->getControlPrototype()->addClass('form-check-input');
|
||||
$control->getSeparatorPrototype()->setName('div')->addClass('form-check');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form = new Form;
|
||||
$form->onRender[] = 'makeBootstrap4';
|
||||
|
||||
$form->addGroup('Personal data');
|
||||
$form->addText('name', 'Your name')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addRadioList('gender', 'Your gender', [
|
||||
'male', 'female',
|
||||
]);
|
||||
|
||||
$form->addCheckboxList('colors', 'Favorite colors', [
|
||||
'red', 'green', 'blue',
|
||||
]);
|
||||
|
||||
$form->addSelect('country', 'Country', [
|
||||
'Buranda', 'Qumran', 'Saint Georges Island',
|
||||
]);
|
||||
|
||||
$form->addCheckbox('send', 'Ship to address');
|
||||
|
||||
$form->addGroup('Your account');
|
||||
$form->addPassword('password', 'Choose password');
|
||||
$form->addUpload('avatar', 'Picture');
|
||||
$form->addTextArea('note', 'Comment');
|
||||
|
||||
$form->addGroup();
|
||||
$form->addSubmit('submit', 'Send');
|
||||
$form->addSubmit('cancel', 'Cancel');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms & Bootstrap v4 rendering example</title>
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
|
||||
<div class="container">
|
||||
<h1>Nette Forms & Bootstrap v4 rendering example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
</div>
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms containers example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
$form = new Form;
|
||||
|
||||
// group First person
|
||||
$form->addGroup('First person');
|
||||
|
||||
$first = $form->addContainer('first');
|
||||
$first->addText('name', 'Your name:');
|
||||
$first->addText('email', 'Email:');
|
||||
$first->addText('street', 'Street:');
|
||||
$first->addText('city', 'City:');
|
||||
|
||||
// group Second person
|
||||
$form->addGroup('Second person');
|
||||
|
||||
$second = $form->addContainer('second');
|
||||
$second->addText('name', 'Your name:');
|
||||
$second->addText('email', 'Email:');
|
||||
$second->addText('street', 'Street:');
|
||||
$second->addText('city', 'City:');
|
||||
|
||||
// group for button
|
||||
$form->addGroup();
|
||||
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms containers example</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
|
||||
<h1>Nette Forms containers example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms custom control example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Nette\Forms\Helpers;
|
||||
use Nette\Utils\Html;
|
||||
|
||||
|
||||
class DateInput extends Nette\Forms\Controls\BaseControl
|
||||
{
|
||||
/** @var string */
|
||||
private $day = '';
|
||||
|
||||
private $month = '';
|
||||
|
||||
private $year = '';
|
||||
|
||||
|
||||
public function __construct($label = null)
|
||||
{
|
||||
parent::__construct($label);
|
||||
$this->setRequired(false)
|
||||
->addRule([__CLASS__, 'validateDate'], 'Date is invalid.');
|
||||
}
|
||||
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
if ($value === null) {
|
||||
$this->day = $this->month = $this->year = '';
|
||||
} else {
|
||||
$date = Nette\Utils\DateTime::from($value);
|
||||
$this->day = $date->format('j');
|
||||
$this->month = $date->format('n');
|
||||
$this->year = $date->format('Y');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return DateTimeImmutable|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return self::validateDate($this)
|
||||
? (new DateTimeImmutable)->setDate((int) $this->year, (int) $this->month, (int) $this->day)->setTime(0, 0)
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isFilled()
|
||||
{
|
||||
return $this->day !== '' || $this->year !== '';
|
||||
}
|
||||
|
||||
|
||||
public function loadHttpData()
|
||||
{
|
||||
$this->day = $this->getHttpData(Form::DATA_LINE, '[day]');
|
||||
$this->month = $this->getHttpData(Form::DATA_LINE, '[month]');
|
||||
$this->year = $this->getHttpData(Form::DATA_LINE, '[year]');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates control's HTML element.
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
$name = $this->getHtmlName();
|
||||
return Html::el('input', [
|
||||
'name' => $name . '[day]',
|
||||
'id' => $this->getHtmlId(),
|
||||
'value' => $this->day,
|
||||
'type' => 'number',
|
||||
'min' => 1,
|
||||
'max' => 31,
|
||||
'data-nette-rules' => Helpers::exportRules($this->getRules()) ?: null,
|
||||
])
|
||||
|
||||
. Helpers::createSelectBox(
|
||||
[1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||
[],
|
||||
$this->month
|
||||
)->name($name . '[month]')
|
||||
|
||||
. Html::el('input', [
|
||||
'name' => $name . '[year]',
|
||||
'value' => $this->year,
|
||||
'type' => 'number',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateDate(Nette\Forms\IControl $control)
|
||||
{
|
||||
return ctype_digit($control->day)
|
||||
&& ctype_digit($control->month)
|
||||
&& ctype_digit($control->year)
|
||||
&& checkdate((int) $control->month, (int) $control->day, (int) $control->year);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Tracy\Debugger::enable();
|
||||
|
||||
$form = new Form;
|
||||
|
||||
$form['date'] = new DateInput('Date:');
|
||||
$form['date']->setDefaultValue(new DateTime);
|
||||
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Tracy\Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms custom control example</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
|
||||
<h1>Nette Forms custom control example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms custom rendering example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Nette\Utils\Html;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
$form = new Form;
|
||||
// setup custom rendering
|
||||
$renderer = $form->getRenderer();
|
||||
$renderer->wrappers['form']['container'] = Html::el('div')->id('form');
|
||||
$renderer->wrappers['group']['container'] = null;
|
||||
$renderer->wrappers['group']['label'] = 'h3';
|
||||
$renderer->wrappers['pair']['container'] = null;
|
||||
$renderer->wrappers['controls']['container'] = 'dl';
|
||||
$renderer->wrappers['control']['container'] = 'dd';
|
||||
$renderer->wrappers['control']['.odd'] = 'odd';
|
||||
$renderer->wrappers['label']['container'] = 'dt';
|
||||
$renderer->wrappers['label']['suffix'] = ':';
|
||||
$renderer->wrappers['control']['requiredsuffix'] = " \xE2\x80\xA2";
|
||||
|
||||
|
||||
$form->addGroup('Personal data');
|
||||
$form->addText('name', 'Your name')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addRadioList('gender', 'Your gender', [
|
||||
'm' => Html::el('span', 'male')->style('color: #248bd3'),
|
||||
'f' => Html::el('span', 'female')->style('color: #e948d4'),
|
||||
]);
|
||||
|
||||
$form->addSelect('country', 'Country', [
|
||||
'Buranda', 'Qumran', 'Saint Georges Island',
|
||||
]);
|
||||
|
||||
$form->addCheckbox('send', 'Ship to address');
|
||||
|
||||
$form->addGroup('Your account');
|
||||
$form->addPassword('password', 'Choose password');
|
||||
$form->addUpload('avatar', 'Picture');
|
||||
$form->addTextArea('note', 'Comment');
|
||||
|
||||
$form->addGroup();
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms custom rendering example</title>
|
||||
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<style>
|
||||
textarea, select, input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="image"]):not([type="range"]) {
|
||||
border: 1px solid #78BD3F;
|
||||
}
|
||||
|
||||
dt, dd {
|
||||
padding: .5em 1em;
|
||||
}
|
||||
|
||||
#form h3 {
|
||||
background: #78BD3F;
|
||||
color: white;
|
||||
margin: 0;
|
||||
padding: .1em 1em;
|
||||
font-size: 100%;
|
||||
font-weight: normal;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
#form dl {
|
||||
background: #F8F8F8;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#form dt {
|
||||
text-align: right;
|
||||
font-weight: normal;
|
||||
float: left;
|
||||
width: 10em;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
#form dd {
|
||||
margin: 0;
|
||||
padding-left: 10em;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#form dd ul {
|
||||
list-style: none;
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
#form dd.odd {
|
||||
background: #EEE;
|
||||
}
|
||||
</style>
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
|
||||
<h1>Nette Forms custom rendering example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms custom validator example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
// Define custom validator
|
||||
class MyValidators
|
||||
{
|
||||
public static function divisibilityValidator($item, $arg)
|
||||
{
|
||||
return $item->value % $arg === 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form = new Form;
|
||||
|
||||
$form->addText('num1', 'Multiple of 8:')
|
||||
->setDefaultValue(5)
|
||||
->addRule('MyValidators::divisibilityValidator', 'First number must be %d multiple', 8);
|
||||
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms custom validator example</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
|
||||
<script>
|
||||
Nette.validators.MyValidators_divisibilityValidator = function(elem, args, val) {
|
||||
return val % args === 0;
|
||||
};
|
||||
</script>
|
||||
|
||||
<h1>Nette Forms custom validator example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms and HTML5.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
$form = new Form;
|
||||
|
||||
$form->addGroup();
|
||||
|
||||
$form->addText('query', 'Search:')
|
||||
->setHtmlType('search')
|
||||
->setHtmlAttribute('autofocus');
|
||||
|
||||
$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]);
|
||||
|
||||
$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]);
|
||||
|
||||
$form->addEmail('email', 'Send to email:')
|
||||
->setHtmlAttribute('autocomplete', 'off')
|
||||
->setHtmlAttribute('placeholder', 'Optional, but Recommended');
|
||||
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms and HTML5</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
|
||||
<h1>Nette Forms and HTML5</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms live validation example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
$form = new Form;
|
||||
$form->addText('name', 'Your name:')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addText('age', 'Your age:')
|
||||
->setRequired('Enter your age')
|
||||
->addRule($form::INTEGER, 'Age must be numeric value')
|
||||
->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);
|
||||
|
||||
$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);
|
||||
|
||||
$form->addPassword('password2', 'Reenter password:')
|
||||
->setRequired('Reenter your password')
|
||||
->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
|
||||
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
$renderer = $form->getRenderer();
|
||||
$renderer->wrappers['pair']['.error'] = 'has-error';
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms live validation example</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.0.0.min.js" integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous"></script>
|
||||
|
||||
<script>
|
||||
function showErrors(errors, focus)
|
||||
{
|
||||
errors.forEach(function(error) {
|
||||
if (error.message) {
|
||||
$(error.element).closest('tr').addClass('has-error').find('.error').remove();
|
||||
$('<span class=error>').text(error.message).insertAfter(error.element);
|
||||
}
|
||||
|
||||
if (focus && error.element.focus) {
|
||||
error.element.focus();
|
||||
focus = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeErrors(elem)
|
||||
{
|
||||
if ($(elem).is('form')) {
|
||||
$('.has-error', elem).removeClass('has-error');
|
||||
$('.error', elem).remove();
|
||||
} else {
|
||||
$(elem).closest('tr').removeClass('has-error').find('.error').remove();
|
||||
}
|
||||
}
|
||||
|
||||
Nette.showFormErrors = function(form, errors) {
|
||||
removeErrors(form);
|
||||
showErrors(errors, true);
|
||||
};
|
||||
|
||||
$(function() {
|
||||
$(':input').keypress(function() {
|
||||
removeErrors(this);
|
||||
});
|
||||
|
||||
$(':input').blur(function() {
|
||||
Nette.formErrors = [];
|
||||
Nette.validateControl(this);
|
||||
showErrors(Nette.formErrors);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<h1>Nette Forms live validation example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
Personal data = Osobní údaje
|
||||
Your name: = Jméno:
|
||||
Enter your name = Zadejte jméno
|
||||
Your age: = Věk:
|
||||
Enter your age = Zadejte váš věk
|
||||
Age must be numeric value = Věk musí být číslo
|
||||
Age must be in range from %d to %d = Věk musí být v rozmezí %d až %d
|
||||
Country: = Země:
|
||||
Select your country = Vyberte zemi
|
||||
World = Svět
|
||||
other = jiná
|
||||
Send = Odeslat
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms localization example.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
class MyTranslator implements Nette\Localization\ITranslator
|
||||
{
|
||||
private $table;
|
||||
|
||||
|
||||
public function __construct(array $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates the given string.
|
||||
*/
|
||||
public function translate($message, $count = null)
|
||||
{
|
||||
return isset($this->table[$message]) ? $this->table[$message] : $message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form = new Form;
|
||||
|
||||
$translator = new MyTranslator(parse_ini_file(__DIR__ . '/localization.ini'));
|
||||
$form->setTranslator($translator);
|
||||
|
||||
$form->addGroup('Personal data');
|
||||
$form->addText('name', 'Your name:')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addText('age', 'Your age:')
|
||||
->setRequired('Enter your age')
|
||||
->addRule($form::INTEGER, 'Age must be numeric value')
|
||||
->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);
|
||||
|
||||
$countries = [
|
||||
'World' => [
|
||||
'bu' => 'Buranda',
|
||||
'qu' => 'Qumran',
|
||||
'st' => 'Saint Georges Island',
|
||||
],
|
||||
'?' => 'other',
|
||||
];
|
||||
$form->addSelect('country', 'Country:', $countries)
|
||||
->setPrompt('Select your country');
|
||||
|
||||
$form->addSubmit('submit', 'Send');
|
||||
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms localization example</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
|
||||
<h1>Nette Forms localization example</h1>
|
||||
|
||||
<?php echo $form ?>
|
||||
|
||||
<footer><a href="https://doc.nette.org/en/forms">see documentation</a></footer>
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Nette Forms manual form rendering.
|
||||
*/
|
||||
|
||||
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
use Nette\Forms\Form;
|
||||
use Tracy\Debugger;
|
||||
use Tracy\Dumper;
|
||||
|
||||
Debugger::enable();
|
||||
|
||||
|
||||
$form = new Form;
|
||||
$form->addText('name')
|
||||
->setRequired('Enter your name');
|
||||
|
||||
$form->addText('age')
|
||||
->setRequired('Enter your age');
|
||||
|
||||
$form->addRadioList('gender', null, [
|
||||
'm' => 'male',
|
||||
'f' => 'female',
|
||||
]);
|
||||
|
||||
$form->addText('email')
|
||||
->setRequired(false)
|
||||
->addRule($form::EMAIL, 'Incorrect email address');
|
||||
|
||||
$form->addSubmit('submit');
|
||||
|
||||
if ($form->isSuccess()) {
|
||||
echo '<h2>Form was submitted and successfully validated</h2>';
|
||||
Dumper::dump($form->getValues());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Nette Forms manual form rendering</title>
|
||||
<link rel="stylesheet" media="screen" href="assets/style.css" />
|
||||
<script src="https://nette.github.io/resources/js/netteForms.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Nette Forms manual form rendering</h1>
|
||||
|
||||
<?php $form->render('begin') ?>
|
||||
|
||||
<?php if ($form->errors): ?>
|
||||
<ul class="error">
|
||||
<?php foreach ($form->errors as $error): ?>
|
||||
<li><?php echo htmlspecialchars($error) ?></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
<fieldset>
|
||||
<legend>Personal data</legend>
|
||||
<table>
|
||||
<tr class="required">
|
||||
<th><?php echo $form['name']->getLabel('Your name:') ?></th>
|
||||
<td><?php echo $form['name']->control->cols(35) ?> <?php echo $form['name']->error ?></td>
|
||||
</tr>
|
||||
<tr class="required">
|
||||
<th><?php echo $form['age']->getLabel('Your age:') ?></th>
|
||||
<td><?php echo $form['age']->control->cols(5) ?> <?php echo $form['age']->error ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $form['gender']->getLabel('Your gender:') ?></th>
|
||||
<td><?php echo $form['gender']->control ?> <?php echo $form['gender']->error ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $form['email']->getLabel('Email:') ?></th>
|
||||
<td><?php echo $form['email']->control->cols(35) ?> <?php echo $form['email']->error ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
<div>
|
||||
<?php echo $form['submit']->getControl('Send') ?>
|
||||
</div>
|
||||
|
||||
<?php $form->render('end'); ?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user