/** * Email template settings in adin * * @param null $defaults * @return Nette\Forms\Form */ public static function emailTemplate($defaults = NULL) { $form = new Form('adminEmailTemplate'); // Email template $form->addGroup('E-mail template'); $formEmail = $form->addContainer('emailType'); $formEmail->addSelect('source', 'E-mail type', array('HTML', 'Plain Text')); $formEmail->addSelect('type', 'E-mail digest type', array('Short Excerpt.', 'Short Excerpt with Featured Image', 'Whole Post (not recommended)')); // Design of e-mail $form->addGroup('E-mail design'); $formDesign = $form->addContainer('emailDesign'); $formDesign->addText('colourBodyBg', 'E-mail background colour')->setType('color')->setOption('description', 'Default: #ececec')->addCondition(Form::FILLED)->addRule(Form::PATTERN, 'Background colour must be a valid hex code.', '^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$'); $formDesign->addText('colourBg', 'Header background colour')->setType('color')->setOption('description', 'Default: #f5f5f5')->addCondition(Form::FILLED)->addRule(Form::PATTERN, 'Background colour must be a valid hex code.', '^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$'); $formDesign->addText('colourTitle', 'Header title colour')->setType('color')->setOption('description', 'Default: #000000')->addCondition(Form::FILLED)->addRule(Form::PATTERN, 'Title colour must be a valid hex code.', '^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$'); $formDesign->addText('colourLinks', 'Links colour')->setType('color')->setOption('description', 'Default: #000000')->addCondition(Form::FILLED)->addRule(Form::PATTERN, 'Link colour must be a valid hex code.', '^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$'); // Social links $form->addGroup('Social Media Links'); $formSocial = $form->addContainer('social'); foreach (Settings::getSocialServices() as $key => $value) { $formSocial->addText($key, $value . ' profile URL')->addCondition(Form::FILLED)->addRule(Form::URL, $value . ' profile URL, must be a valid URL.'); } // Submit $form->addSubmit('submit', 'Save')->setAttribute('class', 'button-primary'); // set dafaults if ($defaults) { $form->setDefaults($defaults); } return $form; }
// 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; } } } else { // not submitted, define default values $defaults = array('name' => 'John Doe', 'userid' => 231, 'country' => 'CZ'); $form->setDefaults($defaults); } // Step 3: Render form ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Nette\Forms custom rendering example | Nette Framework</title> <style type="text/css"> html { font: 16px/1.5 "Trebuchet MS", "Geneva CE", lucida, sans-serif; border-top: 4.7em solid #F4EFE5; }
$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; } ?> <!DOCTYPE html> <meta charset="utf-8"> <title>Nette Forms basic example</title> <link rel="stylesheet" media="screen" href="assets/style.css" /> <script src="http://nette.github.io/resources/js/netteForms.js"></script> <h1>Nette Forms basic example</h1> <?php
/** * @inheritDoc */ public function setDefaults($values, $erase = false) { $values['redirect_uri'] = implode("\n", $values['redirect_uri']); return parent::setDefaults($values, $erase); }
$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>
$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:'******'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:')->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
} 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"]; /* Functions defined in example_library.php */