Example #1
0
$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');
$form->addPassword('password', 'Choose password')->addRule(Form::FILLED, 'Choose your password')->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3)->setOption('description', '(at least 3 characters)');
$form->addPassword('password2', 'Reenter password')->addConditionOn($form['password'], Form::VALID)->addRule(Form::FILLED, 'Reenter your password')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']);
Example #2
0
	'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');

$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');
Example #3
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;
 }
Example #4
0
$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');
// group Your account
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password:'******'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:'******'Reenter your password')->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
$form->addUpload('avatar', 'Picture:')->addCondition($form::FILLED)->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(array('name' => 'John Doe', 'userid' => 231));
if ($form->isSuccess()) {
    echo '<h2>Form was submitted and successfully validated</h2>';
    Dumper::dump($form->getValues());
    exit;
Example #5
0
    /**
     * 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>
Example #6
0
// 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', ['m' => Html::el('option', 'male')->style('color: #248bd3'), 'f' => Html::el('option', '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">
Example #7
0
// 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;
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
Example #8
0
$form->addCheckbox('send', 'Ship to address')
	->addCondition($form::EQUAL, TRUE) // 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::EQUAL, TRUE)
		->addRule($form::FILLED, 'Enter your shipping address');

$form->addSelect('country', 'Country:', $countries)
	->setPrompt('Select your country')
	->addConditionOn($form['send'], $form::EQUAL, TRUE)
		->addRule($form::FILLED, 'Select your country');


// group Your account
$form->addGroup('Your account');

$form->addPassword('password', 'Choose password:'******'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:'******'password'], $form::VALID)
		->addRule($form::FILLED, 'Reenter your password')
Example #9
0
 */
require_once __DIR__ . '/../../Nette/loader.php';
use Nette\Forms\Form, Nette\Debug;
Debug::enable();
$countries = array('Select your country', 'Europe' => array('CZ' => 'Czech Republic', 'SK' => 'Slovakia', 'GB' => 'United Kingdom'), '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)->skipFirst();
$form->addPassword('password');
$form->addPassword('password2');
$form->addFile('avatar');
$form->addHidden('userid');
$form->addTextArea('note');
$form->addSubmit('submit');
// Step 1b: Define validation rules
$form['name']->addRule(Form::FILLED, 'Enter your name');
$form['age']->addRule(Form::FILLED, '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 E-mail Address');
// ... then check email
// another conditional rule: if is checkbox checked...
Example #10
0
$renderer->wrappers['label']['container'] = 'dt';
$renderer->wrappers['label']['suffix'] = ':';
$renderer->wrappers['control']['requiredsuffix'] = " \xE2\x80\xA2";


// 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->addSelect('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


// group Shipping address
$form->addGroup('Shipping address')
	->setOption('embedNext', TRUE);

$form->addCheckbox('send', 'Ship to address')
	->addCondition($form::EQUAL, TRUE) // conditional rule: if is checkbox checked...
		->toggle('sendBox'); // toggle div #sendBox
Example #11
0
 public function addFormControl(\Nette\Forms\Form $form, Builder\Metadata $meta)
 {
     $input = $form->addSelect($meta->name, $meta->label, $this->getValues());
     $this->addConditions($input, $meta->conditions);
     return $input;
 }
Example #12
0
define("APP_DIR", dirname(__FILE__));
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();