/** * @return \Nette\Application\UI\Form */ public function create() { $form = new Form(); $form->addGroup($this->user ? 'Upravit uživatele' : 'Přidat uživatele'); $form->addText("name", 'Jméno:')->setRequired('Vyplňte jméno'); $form->addText("email", 'Email:')->setRequired('Vyplňte email')->addRule(function ($ctrl) { if ($this->user and $this->user->email == $ctrl->getValue()) { return TRUE; } return (bool) (!$this->userFacade->findUserByEmail($ctrl->getValue())); }, 'Email je obsazen, zvolte prosím jiný'); $password = $form->addPassword("password", 'Heslo:'); $password2 = $form->addPassword("password2", 'Heslo znovu:'); if (!$this->user) { $password->setRequired('Vyplňte heslo'); $password2->addRule(Form::FILLED, 'Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password); } else { $password2->addConditionOn($password, Form::FILLED)->setRequired('Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password); } $form->addSubmit("send", $this->user ? 'Upravit uživatele' : 'Přidat uživatele'); $form->setRenderer(new Bs3FormRenderer()); $form->onSuccess[] = $this->processForm; if ($this->user) { $form->setDefaults(["name" => $this->user->name, "email" => $this->user->email]); } return $form; }
public function createComponentForm($name) { $form = new Form($this, $name); $form->addTextArea("html", "Upravte data", 80, 50)->controlPrototype->class[] = "tinymce"; $form->addSubmit("doPDFka", "Do PDFka!"); $appDir = Nette\Environment::getVariable('appDir'); $form->setDefaults(array("html" => $this->createTemplate()->setFile($appDir . "/templates/Homepage/pdf-source.latte")->__toString())); $form->onSuccess[] = array($this, "onSubmit"); }
public function create() { $form = new Form(); $form->addGroup("Set base title"); $form->addText("baseTitle", "Base title:"); $form->addSubmit("send", "Set base title"); $form->onSuccess[] = $this->processForm; $form->setDefaults(array("baseTitle" => $this->settingsDao->getBaseTitle())); return $form; }
public function create() { $form = new Form(); $form->addGroup("Set Google Analytics key"); $form->addText("key", "Google Analytics api key:")->setRequired('Fill Google Analytics api key'); $form->addSubmit("send", "Set Google Analytics key"); $form->onSuccess[] = $this->processForm; $form->setDefaults(array("key" => $this->settingsDao->getGoogleAnalyticsKey())); return $form; }
public function create() { $form = new Form(); $form->addGroup("Set robots.txt"); $form->addTextArea("robots", "Robots.txt content:"); $form->addSubmit("send", "Set robots.txt"); $form->onSuccess[] = $this->processForm; $form->setDefaults(array("robots" => $this->settingsDao->getRobots())); return $form; }
protected function createComponentFormExcelParser() { $form = new Form(); $form->addTextarea('clipboard', 'Clipboard:'); $form->addTextarea('template', 'Template:'); $form->addSubmit('generate', 'Generate'); $form->onSuccess[] = callback($this, 'excelParserFormSubmitted'); $form->setDefaults(array('template' => '{{index}}: {{0}}')); return $form; }
protected function createComponentConsoleForm() { $form = new Form(); $defaults = []; $form->setRenderer(new BootstrapRenderer()); $uri = $this->request->getUrl(); $scheme = $uri->scheme; if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO']; } $port = ''; if ($uri->scheme == 'http' && $uri->port != 80) { $port = ':' . $uri->port; } $url = $scheme . '://' . $uri->host . $port . '/api/' . $this->endpoint->getUrl(); $form->addText('api_url', 'Api Url'); $defaults['api_url'] = $url; $form->addText('method', 'Method'); $defaults['method'] = $this->endpoint->getMethod(); if ($this->authorization instanceof BearerTokenAuthorization) { $form->addText('token', 'Token')->setAttribute('placeholder', 'Enter token'); } elseif ($this->authorization instanceof NoAuthorization) { $form->addText('authorization', 'Authorization')->setDisabled(true); $defaults['authorization'] = 'No authorization - global access'; } $params = $this->handler->params(); foreach ($params as $param) { $count = $param->isMulti() ? 5 : 1; for ($i = 0; $i < $count; $i++) { $key = $param->getKey(); if ($param->isMulti()) { $key = $key . '___' . $i; } if ($param->getAvailableValues() && is_array($param->getAvailableValues())) { $c = $form->addSelect($key, $this->getParamLabel($param), array_combine($param->getAvailableValues(), $param->getAvailableValues())); if (!$param->isRequired()) { $c->setPrompt('Select ' . $this->getLabel($param)); } } elseif ($param->getAvailableValues() && is_string($param->getAvailableValues())) { $c = $form->addText($key, $this->getParamLabel($param))->setDisabled(true); $defaults[$key] = $param->getAvailableValues(); } elseif ($param->getType() == InputParam::TYPE_FILE) { $c = $form->addUpload($key, $this->getParamLabel($param)); } elseif ($param->getType() == InputParam::TYPE_POST_RAW) { $c = $form->addTextArea('post_raw', $this->getParamLabel($param))->setAttribute('rows', 10); } else { $c = $form->addText($key, $this->getParamLabel($param)); } } } $form->addSubmit('send', 'Otestuj')->getControlPrototype()->setName('button')->setHtml('<i class="fa fa-cloud-upload"></i> Try api'); $form->setDefaults($defaults); $form->onSuccess[] = array($this, 'formSucceeded'); return $form; }
public function createComponentObjectForm() { $form = new Form(); $form->addText('name', 'Tag:', NULL, 200)->setRequired(); if ($this->detailObject) { $form->setDefaults(['name' => $this->detailObject->name]); } $form->addSubmit('actionSend', 'Save'); $form->onSuccess[] = array($this, 'objectFormSubmitted'); return $form; }
/** * @return Form */ protected function createComponentForm() { $form = new Form(); $form->getElementPrototype()->class('navbar-form navbar-right'); $form->addText('positive_votes', 'Positive votes to merge')->setRequired('%label is require')->addRule(Form::INTEGER, '%label has to be an integer'); $form->addCheckbox('delete_source_branch', 'Remove source branch when merge request is accepted'); $form->addSubmit('save', 'Save'); $form->onSuccess[] = $this->formSuccess; if ($this->project) { $form->setDefaults($this->project); } return $form; }
protected function createComponentForm() { $form = new UI\Form(); $form->addProtection(); $form->addText('username', 'Uživatelské přihlašovací jméno:')->setRequired('Zadejte prosím přihlašovací jméno.'); $form->addPassword('password', 'Nové heslo k tomuto účtu:')->setRequired('Zadejte prosím své stávající, nebo nové heslo.'); //TODO: toto bude zapotřebí předělat if ($this->presenter->user->isInRole('admin')) { $role = ['admin' => 'Administrátor', 'demo' => 'Demo účet']; $form->addSelect('role', 'Role:', $role); } else { $role = ['demo' => 'Demo účet']; $form->addSelect('role', 'Role:', $role); } if ($this->account) { $form->setDefaults(['username' => $this->account->username]); } else { $form->setDefaults(['role' => 'demo']); } $form->addSubmit('save', 'Uložit změny'); $form->onSuccess[] = $this->formSucceeded; return $form; }
/** * @return \Nette\Application\UI\Form */ public function create() { $form = new Form(); $form->addGroup($this->performance ? "Upravit představení" : "Přidat představení"); $form->addTextArea("songAuthor", "Autor skladby:")->setRequired("Vyplňte prosím autora skladby"); $form->addTextArea("songName", "Jméno skladby:")->setRequired("Vyplňte prosím jméno skladby"); $form->addTextArea("note", "Poznámka:"); $form->addSubmit("send", $this->performance ? "Upravit představení" : "Přidat představení"); $form->onSuccess[] = $this->processForm; if ($this->performance) { $form->setDefaults(["songAuthor" => $this->performance->songAuthor, "songName" => $this->performance->songName, "note" => $this->performance->note]); } return $form; }
protected function createComponentPageForm() { $form = new UI\Form(); $form->addProtection(); $form->addText('title', 'Název:')->setRequired('Je zapotřebí vyplnit název stránky.'); $form->addText('slug', 'URL slug:')->setRequired('Je zapotřebí vyplnit slug.'); $form->addTextArea('editor', 'Obsah stránky:')->setHtmlId('editor')->setRequired('Je zapotřebí napsat nějaký text.'); if ($this->page) { $form->setDefaults(['title' => $this->page->title, 'slug' => $this->page->slug, 'editor' => $this->page->body]); } $form->addSubmit('save', 'Uložit a publikovat'); $form->onSuccess[] = $this->pageFormSucceeded; return $form; }
/** * @return Form */ public function create() { $form = new Form(); $form->addGroup(); $form->addText('username', 'Login:'******'Zadejte prosím uživatelské jméno.'); $form->addPassword('password', 'Heslo:')->setRequired('Zadejte prosím heslo.'); $form->addCheckbox('remember', 'Zůstat přihlášen'); $form->addGroup(); $form->addSubmit('send', 'Přihlásit'); $form->addSubmit('cancel', 'Zpět')->setValidationScope(FALSE); $form->setDefaults(array('username' => 'user', 'password' => NULL, 'remember' => TRUE)); $form->onSuccess[] = array($this, 'formSucceeded'); $form->setRenderer(new Bs3FormRenderer()); return $form; }
/** * @param string $name */ public function createComponentAlbumForm($name) { $form = new Form($this, $name); $form->addText('artist', 'Artist')->setRequired(); $form->addText('albumName', 'Album name')->setRequired(); $form->addText('year', 'Year')->setRequired()->addRule(Form::INTEGER); if ($this->album) { $form->setDefaults(['artist' => $this->album->getArtist(), 'albumName' => $this->album->getAlbumName(), 'year' => $this->album->getYear()]); $form->addSubmit('save', 'Edit album'); $form->onSuccess[] = $this->successEditAlbumForm; } else { $form->addSubmit('save', 'Add new album'); $form->onSuccess[] = $this->successAddAlbumForm; } }
/** * @return Form */ protected function createComponentForm() { $form = new Form(); $form->getElementPrototype()->class('navbar-form navbar-right'); $form->addText('gitlab_url', 'Gitlab API URL')->setAttribute('placeholder', 'https://domain/api/v3'); $form->addText('gitlab_merger_url', 'GitlabMerger URL'); $form->addText('token', 'Automerger user access token'); $form->addSubmit('save', 'Save'); $form->onSuccess[] = $this->formSuccess; $data = $this->settingsRepository->fetch(); if ($data) { $form->setDefaults($data); } return $form; }
protected function createComponentAddEditForm() { $oForm = new Nette\Application\UI\Form(); $oForm->addText('title', "Název")->setRequired(); $oForm->addTextArea('text', "Text")->addRule(Nette\Application\UI\Form::MAX_LENGTH, 'Text je příliš dlouhý', 1000); if ($this->id != 0) { $oForm->addHidden('id'); $oForm->setDefaults($this->template->article); $oForm->addSubmit('send', "Editovat"); } else { $oForm->addSubmit('send', "Přidat"); } $oForm->onSuccess[] = $this->addEditSubmit; return $oForm; }
/** * @return \Nette\Application\UI\Form */ public function create() { $form = new Form(); $form->addGroup($this->event ? "Upravit událost" : "Přidat událost"); $form->addText("name", "Jméno:")->setRequired("Vyplňte prosím jméno"); $form->addText("date", "Datum:")->setAttribute('class', 'datepicker')->setRequired("Vyberte prosím datum"); $form->addText("place", "Místo:")->setRequired("Vyplňte prosím místo"); $form->addTextArea("note", "Poznámka:"); $form->addSubmit("send", $this->event ? "Upravit událost" : "Přidat událost"); $form->onSuccess[] = $this->processForm; if ($this->event) { $form->setDefaults(["name" => $this->event->name, "date" => $this->event->date->format('Y-m-d'), "place" => $this->event->place, "note" => $this->event->note]); } return $form; }
protected function createComponentNewsletterForm() { $events = $this->event->order('id DESC')->limit(10)->fetchPairs('id', 'name'); $events[null] = 'ODESLAT VŠEM'; $form = new UI\Form(); $form->addSelect('event_id', 'Účatníků události', $events); $form->addText('subject', 'Předmět:'); $form->addTextArea('text', 'text')->setAttribute('class', 'tinyMCE'); $form->addCheckbox('notTest', 'TOTO NENÍ TEST'); $form->addMultiUpload('files', 'Přílohy'); $form->addSubmit('send', 'Odeslat')->setAttribute('class', 'btn btn-danger'); $form->onSuccess[] = array($this, 'newsletterFormSucceeded'); $form->setDefaults($this->loadFormValues()); return $form; }
protected function createComponentEditProfileForm() { $form = new Nette\Application\UI\Form(); $form->addText('name', 'Name: ')->setRequired(); $form->addText('email', 'Email: ')->setRequired(); $form->addText('username', 'Username: '******'password', 'Password: '******'about', 'Something about you: ')->setRequired(); //add avatar field //TODO add avatar field $form->addSubmit('send', 'Edit'); $this->userInfo = $this->ur->getUserForId($this->getUser()->id); $defaultValues = array('name' => $this->userInfo->name, 'email' => $this->userInfo->email, 'username' => $this->userInfo->username, 'password' => $this->userInfo->password, 'about' => $this->userInfo->about); $form->setDefaults($defaultValues); $form->onSuccess[] = $this->EditProfileFormSucceeded; return $form; }
protected function createComponentAddEditForm() { $oForm = new Nette\Application\UI\Form(); $oForm->addText('name', "Název")->setRequired(); $oForm->addText('title', "Titulek")->setRequired(); $oForm->addCheckbox('active', "Aktivní menu")->setDefaultValue('checked'); if ($this->id != 0) { $oForm->addHidden('id'); $oForm->setDefaults($this->oModel->getOne($this->id)->toArray()); $oForm->addSubmit('send', "Editovat"); } else { $oForm->addSubmit('send', "Přidat"); } $oForm->onSuccess[] = $this->addEditSubmit; return $oForm; }
class EditPokladnickaFormFactory { /** @var DbTable\Pokladnicka */ private $pokladnicka; /** * @param DbTable\Pokladnicka $pokladnicka * @param DbTable\User_profiles $user_profiles */ public function __construct(DbTable\Pokladnicka $pokladnicka) { $this->pokladnicka = $pokladnicka; } /** * Formular pre pridanie a aditaciu poloziek pokladnicky. * @param int $id Id polozky * @return Nette\Application\UI\Form */ public function create($id = 0) { $form = new Form(); $form->addProtection(); $form->addHidden("id");
/** * @return \Nette\Application\UI\Form */ public function create() { $teacherList = []; foreach ($this->userFacade->getUsersList() as $user) { $teacherList[$user->id] = $user->name; } $form = new Form(); $form->addGroup($this->child ? "Upravit žáka" : "Přidat žáka"); $form->addText("name", "Jméno:")->setRequired("Vyplňte prosím jméno"); $form->addSelect("instrument", "Hudební nástroj", ["klavír" => "klavír", "zob. flétna" => "zob. flétna", "flétna" => "flétna", "klarinet" => "klarinet", "saxofon" => "saxofon", "trubka" => "trubka", "baskřídlovka" => "baskřídlovka", "trombon" => "trombon", "tuba" => "tuba", "bicí nástroje" => "bicí nástroje", "zpěv" => "zpěv", "housle" => "housle", "kontrabas" => "kontrabas", "kytara" => "kytara", "cimbál" => "cimbál", "LDO" => "LDO", "safoxon" => "safoxon", "altsafoxon" => "altsafoxon", "tenorsaxofon" => "tenorsaxofon", "baritonsaxofon" => "baritonsaxofon", "sopránsaxofon" => "sopránsaxofon", "cimbálová muzika" => "cimbálová muzika", "dechová hudba" => "dechová hudba", "komorní hra" => "komorní hra", "komorní zpěv" => "komorní zpěv", "žesťové kvinteto" => "žesťové kvinteto", "žesťové kvarteto" => "žesťové kvarteto", "duo zob. fléten" => "duo zob. fléten", "trio zob. fléten" => "duo zob. fléten", "kytarové duo" => "kytarové duo", "kytarové trio" => "kytarové trio", "taneční obor" => "taneční obor", "klarinetové duo" => "klarinetové duo", "sbor" => "sbor"])->setPrompt("-- Vyberte prosím nástroj --")->setRequired("Vyplňte prosím hudební nástroj"); $form->addSelect("teacher", "Učitel", $teacherList)->setPrompt("-- Bez učitele --"); $form->addSelect("class", "Ročník:", ["PHV" => "PHV", "1. roč. " => "1. roč. ", "2. roč. " => "2. roč. ", "3. roč. " => "3. roč. ", "4. roč. " => "4. roč. ", "5. roč. " => "5. roč. ", "6. roč. " => "6. roč. ", "7. roč. " => "7. roč. ", "1./II. " => "1./II. ", "2./II. " => "2./II. ", "3./II. " => "3./II. ", "4./II. " => "4./II. ", "j. h." => "j. h. "])->setPrompt("-- Bez ročníku --"); $form->addSubmit("send", $this->child ? "Upravit žáka" : "Přidat žáka"); $form->setRenderer(new Bs3FormRenderer()); $form->onSuccess[] = $this->processForm; if ($this->child) { $form->setDefaults(["name" => $this->child->name, "instrument" => $this->child->instrument, "teacher" => $this->child->teacher ? $this->child->teacher->id : null, "class" => $this->child->class]); } return $form; }
public function createComponentExampleOneForm() { $form = new Form(); $form->addText('name', "Name:"); $form->addPassword('password', "Password:"******"Textarea"); $form->addSelect('select', "Select", ['Option 1', 'Option 2']); $form->addUpload('upload', 'Upload'); $form->addCheckbox('checkbox', 'Checkbox'); $form->addRadioList('radioList', 'Radio list', ['Item A', 'Item B']); $form->addCheckboxList('checkboxList', 'Checkbox list,', ['Item A', 'Item B']); $form->addText('date', 'Date:')->getControlPrototype()->class('b-date-input'); $form->addText('datetime', 'Date time:')->getControlPrototype()->class('b-date-input b-date-input--datetime'); $now = new DateTime(); $now->modify('+1 day'); $now->modify('+3 hour'); $form->setDefaults(['date' => $now, 'datetime' => $now]); $form->addSubmit('actionSend', 'Save'); $form->onSuccess[] = array($this, 'exampleOneFormSubmitted'); return $form; }
public function create($defaults, $values) { $form = new Form(); $form->addText('firstName', 'Jméno: ')->setRequired(); $form->addText('surName', 'Příjmení: ')->setRequired(); $form->addText('mail', 'Email: ')->addRule(Form::EMAIL)->setRequired(); $form->addText('telNumber', 'Tel: ')->setRequired(); $form->addSelect('carMakes', 'Značka auta:', $this->carsModel->getCarsMakes())->setRequired(); $form->addText('carModel', 'Model:')->setRequired(); $form->addText('spz', 'Spz: ')->setRequired(); $form->addDatePicker('date', 'Datum:'); $form->addSelect('type', 'Typ služby:', $this->reservationManager->getReservationTypesForSelect()); $form->addSelect('time', 'Čas:', $values); $form->addTextArea('additionalInfo', 'Doplňující informace:'); $form->addSubmit('send', 'Odeslat'); if ($defaults != NULL) { $form->setDefaults($defaults); } $form->onSuccess[] = array($this, 'formSucceeded'); return $form; }
protected function createComponentOptionsForm() { $form = new Form(); $form->setTranslator($this->translator->domain('options.form')); $form->addText('blog_title', 'blogTitle.label', null, 255)->setRequired('blogTitle.messages.required'); $form->addText('blog_subtitle', 'blogSubtitle.label', null, 255); $form->addText('copyright', 'copyright.label', null, 255)->setRequired('copyright.messages.required'); $form->addText('articles_per_page', 'articlesPerPage.label', null, 2)->setRequired('articlesPerPage.messages.required')->addRule(function ($input) { if (Validators::is($input->value, 'numericint:1..')) { return true; } return false; }, 'articlesPerPage.messages.wrongInput'); $form->addText('google_analytics_measure_code', 'gaMeasureCode.label'); $form->addSubmit('save', 'save.caption'); $form->onSuccess[] = [$this, 'processForm']; $form->addProtection(); if (!$this->authorizator->isAllowed($this->user, 'options', 'edit')) { $form['save']->setDisabled(); } $form->setDefaults($this->optionFacade->loadOptions()); return $form; }
protected function createComponentPostForm() { $form = new UI\Form(); $form->addProtection(); $form->addText('title', 'Titulek:')->setRequired('Je zapotřebí vyplnit titulek.'); $form->addText('slug', 'URL slug:')->setRequired('Je zapotřebí vyplnit slug.'); $tags = []; if ($this->post) { foreach ($this->post->tags as $tag) { $tags[] = $tag->name; } } $form->addText('tags', 'Tagy (oddělené čárkou):')->setAttribute('class', 'form-control')->setValue(implode(', ', $tags)); $form->addText('publish_date', 'Datum publikování článku:')->setType('datetime-local'); $form->addTextArea('editor', 'Obsah článku:')->setHtmlId('editor')->setRequired('Je zapotřebí napsat nějaký text.'); $form->addCheckbox('disable_comments', 'Zakázat pod tímto článkem komentáře'); if ($this->post) { $form->setDefaults(['title' => $this->post->title, 'slug' => $this->post->slug, 'editor' => $this->post->body, 'publish_date' => $this->post->publish_date->format('Y-m-d\\TH:i:s'), 'disable_comments' => $this->post->disable_comments]); } $form->addSubmit('save', 'Uložit a publikovat'); $form->onSuccess[] = $this->postFormSucceeded; return $form; }
/** * @return \Nette\Application\UI\Form */ protected function createComponentSettingsServer() { $form = new Form(); $form->addGroup('MC server'); $form->addText('number', "Maximální počet serverů na hráče:")->setAttribute('type', 'number')->addRule(Form::INTEGER, "Hodnota musí být číslo."); $form->addSubmit('send', 'Uložit'); $form->setDefaults($this->configModel->getConfig('server')); $form->onSuccess[] = $this->settingsServerSubmitted; return $form; }
/** * Quick Search form factory. * * @return \Nette\Application\UI\Form */ protected function createComponentQuickSearchForm() { $form = new Form(); $form->setMethod('GET'); $form->addText('q', 'Query:'); $form->addCheckboxList('filter', 'filter', ['light' => 'LIGHT', 'large' => 'LARGE']); $form->addSubmit('search', 'Search'); $filter = []; if ($this->filterLight) { $filter[] = 'light'; } if ($this->filterLarge) { $filter[] = 'large'; } $form->setDefaults(['q' => $this->fulltextQuery, 'filter' => $filter]); $form->onSuccess[] = $this->quickSearchFormSucceeded; return $form; }
public function createComponentPaymentAndShippingForm() { //$countries = $this->context->createReference()->getReference('country')->where('hidden', 0)->order('id')->fetchPairs('id', 'name_full'); $totalPrice = $this->cart->getTotalPrice(\CartItem::ITEM_NORMAL); if ($totalPrice >= $this->noShippingLimit) { $paymentType = $this->context->createReference()->getReference('payment')->where('name_nm', array('BANK'))->order('name_full')->fetchPairs('name_nm', 'name_full'); $shippingTypeBank = $this->context->createReference()->getReference('shipping')->where('name_nm', array('PERSON', 'SAVE', 'DPD'))->order('name_full')->fetchPairs('name_nm', 'name_full'); $shippingTypeCash = $this->context->createReference()->getReference('shipping')->where('name_nm', array())->fetchPairs('name_nm', 'name_full'); $shippingTypeCod = $this->context->createReference()->getReference('shipping')->where('name_nm', array())->fetchPairs('name_nm', 'name_full'); } else { $paymentType = $this->context->createReference()->getReference('payment')->where('name_nm', array('CASH', 'BANK', 'COD'))->order('name_full')->fetchPairs('name_nm', 'name_full'); $shippingTypeCash = $this->context->createReference()->getReference('shipping')->where('name_nm', array('PERSON', 'SAVE'))->fetchPairs('name_nm', 'name_full'); $shippingTypeBank = $this->context->createReference()->getReference('shipping')->where('name_nm', array('PERSON', 'SAVE', 'DPD'))->order('name_full')->fetchPairs('name_nm', 'name_full'); $shippingTypeCod = $this->context->createReference()->getReference('shipping')->where('name_nm', array('DPD'))->fetchPairs('name_nm', 'name_full'); } $saveList = $this->context->createReference()->getReference('save')->where('active', 1)->fetchPairs('id', 'name_full'); $form = new Form(); $form->addGroup('Způsob platby'); $form->addRadioList('payment', 'Způsob platby', $paymentType)->addCondition(Form::EQUAL, 'CASH')->toggle('CASH')->addCondition(Form::EQUAL, 'BANK')->toggle('BANK')->addCondition(Form::EQUAL, 'COD')->toggle('COD'); $form->addGroup('Doprava')->setOption('container', Html::el('fieldset')->id("CASH")->style("display:none")); $form->addRadioList('shippingCash', 'Způsob dopravy', $shippingTypeCash); $form->addSelect('saveListCash', 'Pobočka uloženky', $saveList)->setPrompt('- Vyberte pobočku -'); $form->addGroup('Doprava')->setOption('container', Html::el('fieldset')->id("BANK")->style("display:none")); $form->addRadioList('shippingBank', 'Způsob dopravy', $shippingTypeBank); $form->addSelect('saveListBank', 'Pobočka uloženky', $saveList)->setPrompt('- Vyberte pobočku -'); $form->addGroup('Doprava')->setOption('container', Html::el('fieldset')->id("COD")->style("display:none")); $form->addRadioList('shippingCod', 'Způsob dopravy', $shippingTypeCod); $form->addGroup('Doručovací údaje'); $form->addText('name', 'Jméno:*', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat jméno.')->setAttribute('class', 'text'); $form->addText('surname', 'Příjmení:*', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat příjmení.')->setAttribute('class', 'text'); $form->addText('phone', 'Telefonní číslo:*', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat telefon.')->setAttribute('class', 'text')->addRule(Form::INTEGER, 'Telefon musí být složen jen z čísel.'); $form->addText('email', 'E-mail:*', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat e-mail.')->setAttribute('class', 'text')->addRule(Form::EMAIL, 'Pole email musí obsahovat platnou emailovou adresu.'); $form->addText('street', 'Ulice:*', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat ulici.')->setAttribute('class', 'text'); $form->addText('city', 'Město:*', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat město.')->setAttribute('class', 'text'); $form->addText('zipcode', 'PSČ*:', 40, 100)->addRule(Form::FILLED, 'Je nutné zadat PSČ.')->setAttribute('class', 'text'); $form->addGroup('Poznámka'); $form->addTextArea('note', 'Poznámka k objednávce', 100, 7); if ($this->getUser()->isLoggedIn()) { $form->setDefaults(array('payment' => 'CASH', 'shippingCash' => 'PERSON', 'shippingBank' => 'DPD', 'shippingCod' => 'SAVE', 'name' => $this->customerInformation['name'], 'surname' => $this->customerInformation['surname'], 'phone' => $this->customerInformation['phone'], 'email' => $this->customerInformation['email'], 'street' => $this->customerAddress['street'], 'city' => $this->customerAddress['city'], 'zipcode' => $this->customerAddress['zipcode'], 'country_id' => 1)); } else { $form->setDefaults(array('payment' => 'CASH', 'shippingCash' => 'PERSON', 'shippingBank' => 'DPD', 'shippingCod' => 'SAVE')); } if ($totalPrice >= $this->noShippingLimit) { $form->setDefaults(array('payment' => 'BANK', 'shippingBank' => 'PERSON')); } $form->setCurrentGroup(null); $form->addSubmit('submit', 'Potvrdit')->setAttribute('class', 'button floatLeft')->setAttribute('title', 'Potvrdit'); $form->onSuccess[] = callback($this, 'paymentShippingFormSubmitted'); return $form; }
/** * @author Jiří Šifalda * @param array|\Nette\Forms\Traversable * @param bool * @return \Nette\Forms\Container */ public function setDefaults($values, $erase = false) { if (is_array($values)) { $values = array_map(function ($value) { if (is_object($value) && method_exists($value, '__toString')) { if (isset($value->id)) { return (string) $value->id; } else { return (string) $value; } } return $value; }, $values); } return parent::setDefaults($values, $erase); }