Ejemplo n.º 1
0
 function createComponentLoginForm()
 {
     $form = new Form();
     $form->addText('login')->setAttribute('id', 'login')->setAttribute('class', 'text')->addRule(Form::FILLED, 'Zadejte jméno!');
     $form->addText('password')->setAttribute('id', 'password')->setAttribute('clas', 'text')->addRule(Form::FILLED, 'Zadejte heslo!');
     $form->addSubmit('send')->setAttribute('id', 'Přihlásit')->setAttribute('class', 'ok');
     $form->onSuccess[] = array($this, 'loginFormSucceded');
     return $form;
 }
Ejemplo n.º 2
0
 protected function setupForm(Form $form)
 {
     $uniqueValidator = new UniqueValidator($this->database->table($this->table), $this->getId());
     $form->addText('name', 'Name')->setRequired();
     $form->addText('email', 'Email')->setRequired()->setType('email')->addRule(Form::EMAIL)->addRule($uniqueValidator->validate, 'This email is already registered.');
     $form->addPassword('password', 'Password')->addCondition(Form::FILLED)->addRule(Form::MIN_LENGTH, NULL, 6);
     $roles = array_combine($this->roles, $this->roles);
     $form->addRadioList('role', 'Role', $roles)->setRequired();
     $form->addSubmit('submit', 'Submit');
     $this->onPreSave[] = $this->hashPassword;
 }
Ejemplo n.º 3
0
 protected function setupForm(Form $form)
 {
     $form->addText('name', 'Name')->setRequired();
     $form->addTextArea('description', 'Description')->setAttribute('class', 'editor-standard');
     $form->addText('price', 'Price')->setType('number')->setRequired();
     $form->addUpload('image', 'Image')->addCondition(Form::FILLED)->addRule(Form::IMAGE);
     $form->addText('unit', 'Unit')->setRequired();
     $form->addText('vat', 'Vat Rate')->setType('number')->setRequired();
     $form->addCheckbox('active', 'Active');
     $form->addSubmit('submit', 'Submit');
     $this->onPreSave[] = $this->saveImage;
 }
Ejemplo n.º 4
0
 protected function setupForm(Form $form)
 {
     $form->addText('name', 'Name')->setRequired();
     $form->addTextArea('content', 'Content')->setAttribute('class', 'editor-standard');
     $form->addCheckbox('active', 'Active');
     $form->addSubmit('submit', 'Submit');
 }
Ejemplo n.º 5
0
 public function createComponentArticleForm()
 {
     $form = new Nette\Forms\Form();
     $form->addText('title', 'Název')->setRequired('Název je povinný')->addRule(Form::MAX_LENGTH, 'Délka je maximálně 60 znaků', 60);
     $form->addTextArea('content', 'Obsah')->setRequired();
     $form->addButton('send', 'Přidat');
     $form->onSuccess[] = array($form, function ($form) {
         $values = $form->getValues();
         //doSomething($values->title);
     });
     return $form;
 }
Ejemplo n.º 6
0
 public function addFormControl(\Nette\Forms\Form $form, Builder\Metadata $meta)
 {
     $input = $form->addText($meta->name, $meta->label);
     $input->getControlPrototype()->type('number');
     $input->addCondition(Builder\EntityForm::FILLED)->addRule($meta->type === 'float' ? Builder\EntityForm::FLOAT : Builder\EntityForm::INTEGER);
     if ($meta->type === 'float') {
         $step = isset($meta->custom['step']) ? $meta->custom['step'] : '0.1';
         $input->getControlPrototype()->step($step);
     }
     if (isset($meta->conditions['min'])) {
         $input->getControlPrototype()->min($meta->conditions['min']);
     }
     if (isset($meta->conditions['max'])) {
         $input->getControlPrototype()->max($meta->conditions['max']);
     }
     $this->addConditions($input, $meta->conditions);
     return $input;
 }
Ejemplo n.º 7
0
require_once "../load.php";
require_once "example_library.php";
if (isset($_GET["logConsole"])) {
    require "logConsole.php";
}
use FileDownloader\Downloader\AdvancedDownloader;
use FileDownloader\FDTools;
use FileDownloader\FileDownload;
use Nette\Diagnostics\Debugger;
use Nette\Forms\Form;
// Generate form
$f = new Form("upload-form");
$f->getElementPrototype()->id = "frm";
$f->setMethod("GET");
$f->addSelect("speed", "Speed", array(1 => "1byte/s", 50 => "50bytes/s", 512 => "512bytes/s", 1 * FDTools::KILOBYTE => "1kb/s", 5 * FDTools::KILOBYTE => "5kb/s", 20 * FDTools::KILOBYTE => "20kb/s", 32 * FDTools::KILOBYTE => "32kb/s", 50 * FDTools::KILOBYTE => "50kb/s", 64 * FDTools::KILOBYTE => "64kb/s", 100 * FDTools::KILOBYTE => "100kb/s", 128 * FDTools::KILOBYTE => "128kb/s", 200 * FDTools::KILOBYTE => "200kb/s", 256 * FDTools::KILOBYTE => "256kb/s", 300 * FDTools::KILOBYTE => "300kb/s", 512 * FDTools::KILOBYTE => "512kb/s", 1 * FDTools::MEGABYTE => "1mb/s", 2 * FDTools::MEGABYTE => "2mb/s", 5 * FDTools::MEGABYTE => "5mb/s", 10 * FDTools::MEGABYTE => "10mb/s", 0 => "Unlimited"));
$f->addText("filename", "Filename")->addRule(Form::FILLED, "You must fill name!");
$f->addSelect("size", "Size", array(1 => "1MB", 4 => "4MB", 8 => "8MB", 16 => "16MB", 32 => "32MB", 64 => "64MB", 128 => "128MB", 256 => "256MB", 512 => "512MB"));
$f->addSelect("log", "Log called events?", array(0 => "No", 1 => "Yes (may cause CPU load)"));
$f->addSubmit("download", "Download!");
$f->setDefaults(array("speed" => 50, "filename" => "Some horrible file name - ěščřžýáíé.bin", "size" => 8, "log" => 1));
if ($f->isSubmitted() and $f->isValid()) {
    Debugger::enable(Debugger::PRODUCTION);
    // Log errors to file!
    $val = $f->getValues();
    $location = dirname(__FILE__) . "/cache/test-" . $val["size"] . "MB.tmp";
    if (!file_exists($location)) {
        generateFile($location, $val["size"] * 1024);
    }
    /* Interface with getters and setters */
    $file = new FileDownload();
    $file->sourceFile = $location;
Ejemplo n.º 8
0
	'm' => 'male',
	'f' => 'female',
);



// Step 1: Define form with validation rules
$form = new Form;
// enable translator
$translator = new MyTranslator('gettext', __DIR__ . '/messages.mo', 'cs');
$translator->setLocale('cs');
$form->setTranslator($translator);

// group Personal data
$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', array(10, 100));

$form->addRadioList('gender', 'Your gender:', $sex);

$form->addText('email', 'Email:')
	->setEmptyValue('@')
	->addCondition($form::FILLED) // conditional rule: if is email filled, ...
		->addRule($form::EMAIL, 'Incorrect email address'); // ... then check email

Ejemplo n.º 9
0
<div class="page-header">
  <h1>
    <i class="fa fa-plus"></i> Add a new station log
  </h1>
</div>
<?php 
use Nette\Forms\Form;
use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
$form = new Form();
$form->setRenderer(new BootstrapRenderer());
$form->addProtection();
$form->addText('reporter', 'Nickname')->setAttribute('placeholder', 'anonymous')->setRequired();
date_default_timezone_set("UTC");
$form->addText('datetime', 'When')->setAttribute('placeholder', '2014-01-01 14:00')->setDefaultValue(date('Y-m-d H:i:s'))->setRequired();
$form->addText('station', 'Station designator')->setRequired()->setAttribute('placeholder', 'E11');
$form->addText('qrh', 'Frequency')->setRequired()->setAttribute('placeholder', '4625')->addRule(Form::FLOAT);
$form->addText('callnumber', 'Call # (leave empty if not captured)')->setAttribute('placeholder', '472 639 5 or 441/30');
$form->addText('callid', 'Call ID (leave empty if not captured)')->setAttribute('placeholder', '472 639 5 or 441/30');
$form->addText('gc', 'Group Count')->setAttribute('placeholder', '10');
$form->addTextArea('body', 'Message (leave empty if not captured)')->setAttribute('placeholder', '39715 12345');
$form->addSubmit('send', 'Add to our mighty database');
if ($form->isSuccess() && $form->isValid()) {
    //die();
    $f = $form->getValues();
    //dump($f);
    $arr = array('time' => $f['datetime'], 'station' => $f['station'], 'qrh' => $f['qrh'], 'call_number' => $f['callnumber'], 'call_id' => $f['callid'], 'gc' => $f['gc'], 'body' => $f['body'], 'reporter' => $f['reporter']);
    dibi::query('insert into logs_new', $arr);
    echo "Log has been added. Thank you.";
}
$form->render();
Ejemplo n.º 10
0
if (@!include __DIR__ . '/../vendor/autoload.php') {
	die('Install packages using `composer update --dev`');
}

use Nette\Forms\Form;
use Nette\Forms\Controls;
use Tracy\Debugger;
use Tracy\Dumper;

Debugger::enable();


$form = new Form;

$form->addGroup('Personal data');
$form->addText('name', 'Your name')
	->setRequired('Enter your name');

$form->addRadioList('gender', 'Your gender', array(
	'male', 'female',
));

$form->addCheckboxList('colors', 'Favorite colors:', array(
	'red', 'green', 'blue',
));

$form->addSelect('country', 'Country', array(
	'Buranda', 'Qumran', 'Saint Georges Island',
));

$form->addCheckbox('send', 'Ship to address');
Ejemplo n.º 11
0
		<script src="js/jquery.js"></script>
		<script src="js/netteForms.js"></script>
		<script src="js/main.js"></script>
	</head>
	<body>
		
		<div style="width: 800px;">
			
		<?php 
echo "<h2>" . date('d.m.Y H:i:s') . "</h2>";
$form = new Form();
$form->addHidden('general', '[GENERAL]');
$form->addHidden('file');
$form->addGroup('B7 setting');
$form->addHidden('b7', '[B7]');
$form->addText('stanoviste', 'Číslo stanoviště:')->setOption('description', 'Zadejte číslo stanoviště od 1 do 999')->setRequired('Zadejte číslo od 1 do 999')->addRule(Form::INTEGER, 'Stanoviště musí být číslo')->addRule(Form::RANGE, 'Číslo musí být od 1 do 99', array(1, 999))->setType('number');
$form->addHidden('cards');
$form->addHidden('ftp', '[FTP]');
$form->addHidden('server');
$form->addHidden('user');
$form->addHidden('password');
$form->addHidden('dstdir');
$form->addHidden('db', '[DB]');
$form->addHidden('script');
$form->addHidden('dbserver');
$form->addHidden('dbport');
$form->addHidden('dbuser');
$form->addHidden('dbpassword');
$form->addHidden('dbname');
$form->addHidden('dbtablename');
$form->addSubmit('send', 'Uložit');
Ejemplo n.º 12
0
<?php

/**
 * Nette\Forms custom validator example.
 */
require_once __DIR__ . '/../../Nette/loader.php';
use Nette\Forms\Form, Nette\Debug;
Debug::enable();
// Step 0: Define custom validator
function myValidator($item, $arg)
{
    return $item->getValue() % $arg === 0;
}
// Step 1: Define form with validation rules
$form = new Form();
$form->addText('num1', 'Multiple of 8:')->addRule('myValidator', 'First number must be %d multiple', 8);
$form->addText('num2', 'Not multiple of 5:')->addRule(~'myValidator', 'Second number must not be %d multiple', 5);
// negative
$form->addSubmit('submit', 'Send');
// Step 2: Check if form was submitted?
if ($form->isSubmitted()) {
    // Step 2c: Check if form is valid
    if ($form->isValid()) {
        echo '<h2>Form was submitted and successfully validated</h2>';
        $values = $form->getValues();
        Debug::dump($values);
        // this is the end, my friend :-)
        if (empty($disableExit)) {
            exit;
        }
    }
Ejemplo n.º 13
0
 */
if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
    die('Install packages using `composer install`');
}
use Nette\Forms\Form, Tracy\Debugger, Tracy\Dumper;
Debugger::enable();
// Define custom validator
class MyValidators
{
    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->addText('num2', 'Not multiple of 5:')->setDefaultValue(5)->addRule(~'MyValidators::divisibilityValidator', 'Second number must not be %d multiple', 5);
// negative
$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="http://nette.github.io/resources/js/netteForms.js"></script>
Ejemplo n.º 14
0
/**
 * Nette Forms basic example.
 */
if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
    die('Install packages using `composer install`');
}
use Nette\Forms\Form;
use Tracy\Debugger;
use Tracy\Dumper;
use Nette\Utils\Html;
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', array(10, 100));
$form->addRadioList('gender', 'Your gender:', array('m' => 'male', 'f' => 'female'));
$form->addCheckboxList('colors', 'Favorite colors:', array('r' => 'red', 'g' => 'green', 'b' => 'blue'));
$form->addText('email', 'Email:')->setEmptyValue('@')->addCondition($form::FILLED)->addRule($form::EMAIL, 'Incorrect email address');
// ... then check email
// group Shipping address
$form->addGroup('Shipping address')->setOption('embedNext', TRUE);
$form->addCheckbox('send', 'Ship to address')->addCondition($form::FILLED)->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 = array('World' => array('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');
Ejemplo n.º 15
0
<?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:')->setType('search')->setAttribute('autofocus');
$form->addText('count', 'Number of results:')->setType('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:')->setType('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:')->setAttribute('autocomplete', 'off')->setAttribute('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>
Ejemplo n.º 16
0
		<meta name="viewport" content="width=device-width">
		<link rel="stylesheet" href="css/bootstrap.css">
		<link rel="stylesheet" href="css/b7.css">
		<script src="js/jquery.js"></script>
		<script src="js/netteForms.js"></script>
		<script src="js/main.js"></script>
	</head>
	<body>
		
		<div style="width: 900px;">
		<?php 
echo "<h2>" . date('d.m.Y H:i:s') . "</h2>";
$form = new Form();
$form->addGroup('GENERAL setting');
$form->addHidden('general', '[GENERAL]');
$form->addText('file', 'soubor:')->setOption('description', Html::el('b')->setHtml('/home/pi/b7/vysledky.log Cesta pro umisteni souboru !!'))->setRequired('Zadejte název souboru');
$form->addGroup('B7 setting');
$form->addHidden('b7', '[B7]');
$form->addText('stanoviste', 'Číslo stanoviště:')->setOption('description', 'Zadejte číslo stanoviště od 1 do 999')->setRequired('Zadejte číslo od 1 do 999')->addRule(Form::INTEGER, 'Stanoviště musí být číslo')->addRule(Form::RANGE, 'Číslo musí být od 1 do 99', array(1, 999))->setType('number');
$form->addTextArea('cards', 'Service cards:')->setOption('description', 'Zadejte čísla karet v hexadecimalnim formatu oddělené "|"')->setRequired('Zadejte číslo karty ve formátu hexa|hexa')->addRule(Form::PATTERN, 'cards neplatný formát hexa|hexa', '^(([a-fA-F0-9]){8})(\\|(([a-fA-F0-9]){8}))*$');
$form->addGroup('FTP setting');
$form->addHidden('ftp', '[FTP]');
$form->addText('ftpserver', 'server:')->setOption('description', 'Zadejte adresu ftp serveru')->setRequired('Zadejte adresu ftp serveru');
$form->addText('ftpuser', 'user:'******'description', 'Zadejte uživatelské jméno')->setRequired('Zadejte uživatelské jméno');
$form->addText('ftppassword', 'heslo:')->setOption('description', 'Zadejte heslo')->setRequired('Zadejte heslo');
$form->addText('ftpdstdir', 'Cílový adresář:')->setOption('description', 'Zadejte název cílového adresáře kde bude uložen soubor s logy /log')->setRequired('Zadejte název cílového adresáře');
$form->addGroup('MYSQL setting');
$form->addHidden('db', '[DB]');
$form->addText('script', 'Ceata ke skriptu: ')->setOption('description', Html::el('b')->setHtml('/home/pi/b7/b7_mysql.sh Nevyplněno znamená neodesílat data přímo do databáze !!'));
$form->addText('dbserver', 'server:')->setOption('description', 'Zadejte adresu mysql serveru');
$form->addText('dbport', 'port:')->setOption('description', 'Zadejte port mysql serveru obykle 3306')->addRule(Form::INTEGER, 'Port musí být číslo')->setType('number');
Ejemplo n.º 17
0
<?php

/**
 * Nette Forms manual form rendering.
 */
if (@(!(include __DIR__ . '/../../Nette/loader.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, array('m' => 'male', 'f' => 'female'));
$form->addText('email')->addCondition($form::FILLED)->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>
Ejemplo n.º 18
0
Debugger::enable();


// Define custom validator
class MyValidators
{
	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->addText('num2', 'Not multiple of 5:')
	->setDefaultValue(5)
	->addRule(~'MyValidators::divisibilityValidator', 'Second number must not be %d multiple', 5); // negative

$form->addSubmit('submit', 'Send');


if ($form->isSuccess()) {
	echo '<h2>Form was submitted and successfully validated</h2>';
	Dumper::dump($form->getValues());
	exit;
}
Ejemplo n.º 19
0
    die('Install packages using `composer install`');
}
use Nette\Forms\Form;
use Tracy\Debugger;
use Tracy\Dumper;
Debugger::enable();
// Define custom validator
class MyValidators
{
    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) {
Ejemplo n.º 20
0
 */


if (@!include __DIR__ . '/../vendor/autoload.php') {
	die('Install packages using `composer update --dev`');
}

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, array(
	'm' => 'male',
	'f' => 'female',
));

$form->addText('email')
	->addCondition($form::FILLED)
		->addRule($form::EMAIL, 'Incorrect email address');

$form->addSubmit('submit');
Ejemplo n.º 21
0
use Nette\Forms\Form;
?>
<html>
	<head>
		 <title>B7 time setting</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width">
		<link rel="stylesheet" href="css/bootstrap.css">
		<link rel="stylesheet" href="css/b7.css">
		<script src="js/jquery.js"></script>
		<script src="js/netteForms.js"></script>
		<script src="js/main.js"></script>
	</head>
	<body>
		<?php 
$form = new Form();
$form->addGroup('GENERAL setting');
$form->addHidden('general', '[GENERAL]');
$form->addText('datetime', 'Datum a čas:')->setOption('description', 'Zadejte název souboru')->setRequired('Zadejte název souboru');
$form->addSubmit('send', 'Uložit');
$form->setDefaults($ini_array);
echo $form;
// vykreslí formulář
if ($form->isSuccess()) {
    $values = $form->getValues(true);
    echo "\t<script>\r\n\t\t\t\t\t\t\talert('Formulář byl uložen');\r\n\t\t\t\t\t\t\twindow.location.replace('time.php');\r\n\t\t\t\t\t\t</script>)";
}
?>
		
	</body>
</html>
Ejemplo n.º 22
0
<?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>
Ejemplo n.º 23
0
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'] = " •";
$form->addGroup('Personal data');
$form->addText('name', 'Your name')->setRequired('Enter your name');
$form->addRadioList('gender', 'Your gender', array('m' => Html::el('option', 'male')->style('color: #248bd3'), 'f' => Html::el('option', 'female')->style('color: #e948d4')));
$form->addSelect('country', 'Country', array('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;
}
?>
Ejemplo n.º 24
0
<?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:')->setType('search')->setAttribute('autofocus');
$form->addText('count', 'Number of results:')->setType('number')->setDefaultValue(10)->addRule($form::INTEGER, 'Must be numeric value')->addRule($form::RANGE, 'Must be in range from %d to %d', array(1, 100));
$form->addText('precision', 'Precision:')->setType('range')->setDefaultValue(50)->addRule($form::INTEGER, 'Precision must be numeric value')->addRule($form::RANGE, 'Precision must be in range from %d to %d', array(0, 100));
$form->addText('email', 'Send to email:')->setType('email')->setAttribute('autocomplete', 'off')->setAttribute('placeholder', 'Optional, but Recommended')->addCondition($form::FILLED)->addRule($form::EMAIL, 'Incorrect email address');
// ... then check email
$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="http://nette.github.io/resources/js/netteForms.js"></script>
Ejemplo n.º 25
0
    {
        $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>
Ejemplo n.º 26
0
 /**
  * Email subscribers
  *
  * @return \Nette\Forms\Form
  */
 public static function email(array $get)
 {
     $form = new Form('adminEmail');
     // Prepare
     if (isset($get['action']) && $get['action'] == 'email') {
         $preFill = TRUE;
     } else {
         $preFill = FALSE;
     }
     $emailWhoDefault = $preFill ? 2 : 1;
     $emailSubscriberDefault = isset($get['email']) ? $get['email'] : '';
     // Email subscribers
     $form->addGroup('E-mail Subscriber(s)');
     $form->addSelect('emailWho', 'Recipient(s)', array(1 => 'All subscriber(s)', 2 => 'Single Subscriber', 3 => 'Wordpress Registered subscribers', 4 => 'Non-wordpress Registered subscribers'))->setDefaultValue($emailWhoDefault)->addCondition(Form::EQUAL, 2)->toggle("subscriber");
     $form->addGroup()->setOption('container', Html::el('fieldset')->id("subscriber"));
     $form->addText("email", "Subscriber")->setDefaultValue($emailSubscriberDefault)->addCondition(Form::FILLED)->addRule(Form::EMAIL, 'Must be valid e-mail address');
     $form->addGroup();
     $form->addText('subject', 'Subject')->setRequired('Subject is required');
     $form->addTextArea('body', 'E-mail message')->setRequired('You don\'t want to send an empty message now do you :)');
     // Submit
     $form->addSubmit('submit', 'Send')->setAttribute('class', 'button-primary');
     return $form;
 }
Ejemplo n.º 27
0
	),
	'CA' => 'Canada',
	'US' => 'United States',
	'?'  => 'other',
);

$sex = array(
	'm' => 'male',
	'f' => 'female',
);



// Step 1: Define form
$form = new Form;
$form->addText('name');
$form->addText('age');
$form->addRadioList('gender', NULL, $sex);
$form->addText('email')->setEmptyValue('@');

$form->addCheckbox('send');
$form->addText('street');
$form->addText('city');
$form->addSelect('country', NULL, $countries)->setPrompt('Select your country');

$form->addPassword('password');
$form->addPassword('password2');
$form->addUpload('avatar');
$form->addHidden('userid');
$form->addTextArea('note');
Ejemplo n.º 28
0
if (@!include __DIR__ . '/../vendor/autoload.php') {
	die('Install packages using `composer update --dev`');
}

use Nette\Forms\Form;
use Tracy\Debugger;
use Tracy\Dumper;

Debugger::enable();


$form = new Form;

$form->addGroup();

$form->addText('query', 'Search:')
	->setType('search')
	->setAttribute('autofocus');

$form->addText('count', 'Number of results:')
	->setType('number')
	->setDefaultValue(10)
	->addRule($form::INTEGER, 'Must be numeric value')
	->addRule($form::RANGE, 'Must be in range from %d to %d', array(1, 100));

$form->addText('precision', 'Precision:')
	->setType('range')
	->setDefaultValue(50)
	->addRule($form::INTEGER, 'Precision must be numeric value')
	->addRule($form::RANGE, 'Precision must be in range from %d to %d', array(0, 100));
Ejemplo n.º 29
0
$renderer = $form->getRenderer();
$renderer->wrappers['form']['container'] = Html::el('div')->id('form');
$renderer->wrappers['form']['errors'] = FALSE;
$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['control']['errors'] = TRUE;
$renderer->wrappers['label']['container'] = 'dt';
$renderer->wrappers['label']['suffix'] = ':';
$renderer->wrappers['control']['requiredsuffix'] = " •";
// group Personal data
$form->addGroup('Personal data');
$form->addText('name', 'Your name')->addRule(Form::FILLED, 'Enter your name');
$form->addText('age', 'Your age')->addRule(Form::FILLED, 'Enter your age')->addRule(Form::INTEGER, 'Age must be numeric value')->addRule(Form::RANGE, 'Age must be in range from %d to %d', array(10, 100));
$form->addSelect('gender', 'Your gender', $sex);
$form->addText('email', 'E-mail')->setEmptyValue('@')->addCondition(Form::FILLED)->addRule(Form::EMAIL, 'Incorrect E-mail Address');
// ... then check email
// group Shipping address
$form->addGroup('Shipping address')->setOption('embedNext', TRUE);
$form->addCheckbox('send', 'Ship to address')->addCondition(Form::EQUAL, TRUE)->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::EQUAL, TRUE)->addRule(Form::FILLED, 'Enter your shipping address');
$form->addSelect('country', 'Country', $countries)->skipFirst()->addConditionOn($form['send'], Form::EQUAL, TRUE)->addRule(Form::FILLED, 'Select your country');
// group Your account
$form->addGroup('Your account');
Ejemplo n.º 30
0
/**
 * Nette Forms basic example.
 */
if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
    die('Install packages using `composer install`');
}
use Nette\Forms\Form;
use Tracy\Debugger;
use Tracy\Dumper;
use Nette\Utils\Html;
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)->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