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'); }
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; }
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; }
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; }
* @package RadekDostal\NetteComponents\DateTimePicker * @example https://componette.com/radekdostal/nette-datetimepicker/ * @author Ing. Radek Dostál, Ph.D. <*****@*****.**> * @copyright Copyright (c) 2010 - 2016 Radek Dostál * @license GNU Lesser General Public License * @link http://www.radekdostal.cz */ use Nette\Forms\Form; use Tracy\Debugger; require '../vendor/autoload.php'; Debugger::$strictMode = TRUE; Debugger::enable(); RadekDostal\NetteComponents\DateTimePicker\DateTimePicker::register(); $form = new Form(); $form->addDateTimePicker('datetime', 'Date and time:', 16)->setRequired()->setAttribute('size', 16); $form->addSubmit('submit', 'Send'); if ($form->isSuccess() === TRUE) { echo '<h2>Form was submitted and successfully validated</h2>'; Debugger::dump($form->getValues()); exit; } /*else { $form->setDefaults(array( 'datetime' => new \DateTime() )); }*/ ?> <!DOCTYPE html> <html lang="en" dir="ltr"> <head>
/** * 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; }
$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'); $form->addSubmit('submit'); // Step 1b: Define validation rules $form['name']->setRequired('Enter your name'); $form['age']->setRequired('Enter your age'); $form['age']->addRule($form::INTEGER, 'Age must be numeric value'); $form['age']->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100)); // conditional rule: if is email filled, ... $form['email']->addCondition($form::FILLED) ->addRule($form::EMAIL, 'Incorrect email address'); // ... then check email // another conditional rule: if is checkbox checked... $form['send']->addCondition($form::EQUAL, TRUE)
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'); $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; } // setup form rendering $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';
* @example https://componette.com/radekdostal/nette-datetimepicker/ * @author Ing. Radek Dostál, Ph.D. <*****@*****.**> * @copyright Copyright (c) 2014 - 2016 Radek Dostál * @license GNU Lesser General Public License * @link http://www.radekdostal.cz */ use Nette\Forms\Form; use Tracy\Debugger; require '../vendor/autoload.php'; Debugger::$strictMode = TRUE; Debugger::enable(); RadekDostal\NetteComponents\DateTimePicker\TbDateTimePicker::register(); $form = new Form(); $form->getElementPrototype()->class('form-horizontal'); $form->addTbDateTimePicker('date', 'Date and time:')->setRequired()->setAttribute('class', 'form-control')->getLabelPrototype()->setAttribute('class', 'control-label col-sm-3'); $form->addSubmit('submit', 'Send')->setAttribute('class', 'btn btn-default'); if ($form->isSuccess() === TRUE) { echo '<h2>Form was submitted and successfully validated</h2>'; Debugger::dump($form->getValues()); exit; } /*else { $form->setDefaults(array( 'date' => new \DateTime() )); }*/ ?> <!DOCTYPE html> <html lang="en" dir="ltr"> <head>
$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'); $form->setDefaults($ini_array); echo $form; // vykreslí formulář if ($form->isSuccess()) { $values = $form->getValues(true); if ($IniFile->write_php_ini($values)) { echo "\t<script>\n\t\t\t\t\t\t\talert('Formulář byl uložen');\n\t\t\t\t\t\t\twindow.location.replace('index.php');\n\t\t\t\t\t\t</script>)"; } } ?> </div> </body> </html>
<?php /** * Nette\Forms Cross-Site Request Forgery (CSRF) protection example. */ require_once __DIR__ . '/../../Nette/loader.php'; use Nette\Forms\Form, Nette\Debug; Debug::enable(); $form = new Form(); $form->addProtection('Security token did not match. Possible CSRF attack.', 3); $form->addHidden('id')->setDefaultValue(123); $form->addSubmit('submit', 'Delete item'); // 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; } } } // Step 3: Render form ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8">
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; $file->transferFileName = $val["filename"]; $file->speedLimit = (int) $val["speed"]; //$file->mimeType = $val["mimeType"];
<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();
<div class="page-header"> <h1><i class="fa fa-search"></i> Search</h1> </div> <h2>Station logs</h2> <?php // temporary until we get a list of stations use Nette\Forms\Form; use Kdyby\BootstrapFormRenderer\BootstrapRenderer; $form = new Form(); $form->setRenderer(new BootstrapRenderer()); $form->setAction('/list'); $form->setMethod('GET'); //$form->addProtection(); $form->addText('station', 'Station')->setAttribute('placeholder', 'E11')->setRequired(); $form->addSubmit('search', 'Search for this station'); $form->render();