Adds fieldset group to the form.
public addGroup ( $caption = NULL, $setAsCurrent = TRUE ) : |
||
return |
/** * 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; }
// setup custom rendering $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
<?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>
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; // 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:');
<?php /** * 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');
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" />
use Nette\Utils\Html; 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; }
$sex = array( '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
<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: 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');
<title>B7 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> <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 !!'));
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>