public function createComponent($name) { switch ($name) { case 'settingsForm': $form = new AppForm($this, $name); // basic $form->addGroup(__('Basic')); $form->addText('shopName', __('Shop name:'))->addRule(Form::FILLED, __('You have to entry shop name.')); $form->addText('shopSlogan', __('Shop slogan:'))->addRule(Form::FILLED, __('You have to entry shop slogan.')); $form->addText('shopEmail', __('Contact e-mail:'))->addRule(Form::FILLED, __('You have to entry contact e-mail.')); // address $form->addGroup(__('Shop address')); $form->addText('shopAddressCompany', __('Company:')); $form->addText('shopAddressName', __('Name:'))->addRule(Form::FILLED, __('You have to entry name.')); $form->addText('shopAddressStreet', __('Street:'))->addRule(Form::FILLED, __('You have to entry street.')); $form->addText('shopAddressCity', __('City:'))->addRule(Form::FILLED, __('You have to entry city.')); $form->addText('shopAddressPostcode', __('Post code:'))->addRule(Form::FILLED, __('You have to entry post code.')); // miscellaneous $form->addGroup(__('Miscellaneous')); $form->addText('metaKeywords', __('META keywords:'))->addRule(Form::FILLED, __('You have to entry META keywords.')); $form->addText('metaDescription', __('META description:'))->addRule(Form::FILLED, __('You have to entry META description.')); $form->addText('currency', __('Currency:'))->addRule(Form::FILLED, __('You have to entry currency.')); $form->addText('itemsPerPage', __('Items per page:'))->addRule(Form::FILLED, __('You have to entry items per page.'))->addRule(Form::FILLED, __('Items per page has to be a number.')); $themes = array(0 => __('–––')); foreach (new DirectoryIterator(Environment::expand('%themeDir%')) as $_) { if (!$_->isDot() && $_->isDir()) { $themes[$_->getFilename()] = $_->getFilename(); } } $form->addSelect('theme', __('Theme:'), $themes)->skipFirst(); $form['theme']->addRule(Form::FILLED, __('You have to select theme.')); // submit $form->setCurrentGroup(NULL); $form->addSubmit('ok', '✔ ' . __('Save')); $form->onSubmit[] = array($this, 'onSettingsFormSubmit'); break; case 'changeLoginForm': $form = new AppForm($this, $name); $form->addText('username', __('Username:'******'You have to entry username.')); $form->addPassword('old_password', __('Old password:'******'You have to entry old password.')); $form->addPassword('new_password', __('New password:'******'You have to entry new password.')); $form->addPassword('new_password_again', __('New password (again):'))->addRule(Form::FILLED, __('You have to entry new password again.'))->addRule(Form::EQUAL, __('New passwords have to match.'), $form['new_password']); $form->addSubmit('ok', '✔ ' . __('Change')); $form->onSubmit[] = array($this, 'onChangeLoginFormSubmit'); break; default: parent::createComponent($name); } }
/** * A little componen factory * @param string */ public function createComponent($name) { switch ($name) { case 'dataForm': $data = isset(Environment::getSession(SESSION_ORDER_NS)->data) ? Environment::getSession(SESSION_ORDER_NS)->data : array(); $form = new AppForm($this, $name); // contacts $form->addGroup(__('Contacts')); $form->addText('email', __('E-mail:'))->setEmptyValue('@')->addRule(Form::FILLED, __('You have to enter your e-mail.'))->addRule(Form::EMAIL, __('This is not an e-mail address.')); $form->addText('phone', __('Phone number:'))->addRule(Form::FILLED, __('You have to enter your phone number.'))->addRule(Form::NUMERIC, __('Phone number has to be number.')); // payer $form->addGroup(__('Payer')); $form->addText('payer_name', __('Name:'))->addRule(Form::FILLED, __('You have to enter your name.')); $form->addText('payer_lastname', __('Last name:'))->addRule(Form::FILLED, __('You have to enter your last name.')); $form->addText('payer_company', __('Company:')); $form->addText('payer_street', __('Street:'))->addRule(Form::FILLED, __('You have to enter your street.')); $form->addText('payer_city', __('City:'))->addRule(Form::FILLED, __('You have to enter your city.')); $form->addText('payer_postcode', __('Post code:'))->addRule(Form::FILLED, __('You have to enter your post code.'))->addRule(Form::NUMERIC, __('Post code has to be number.')); $form->addCheckbox('same_delivery', __('deliver at same address (you do not need to fill Delivery address below)'))->setValue(TRUE); // delivery address $form->addGroup(__('Delivery address')); $form->addText('delivery_name', __('Name:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your name.')); $form->addText('delivery_lastname', __('Last name:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your last name.')); $form->addText('delivery_street', __('Street:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your street.')); $form->addText('delivery_city', __('City:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your city.')); $form->addText('delivery_postcode', __('Post code:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your post code.'))->addRule(Form::NUMERIC, __('Post code has to be number.')); // delivery type $form->addGroup(__('Delivery type')); $delivery_types = array(); foreach (mapper::order_delivery_types()->findAll() as $delivery_type) { $delivery_types[$delivery_type->getId()] = $delivery_type->getName() . Environment::expand(' (' . $delivery_type->getPrice() . ' %currency%)'); } $form->addSelect('delivery_type', __('Type:'), $delivery_types); // payment type $form->addGroup(__('Payment type')); $payment_types = array(); foreach (mapper::order_payment_types()->findAll() as $payment_type) { $payment_types[$payment_type->getId()] = $payment_type->getName() . Environment::expand(' (' . $payment_type->getPrice() . ' %currency%)'); } $form->addSelect('payment_type', __('Type:'), $payment_types); // comment $form->addGroup(__('Comment')); $form->addTextarea('comment', __('Comment:')); // submit $form->setCurrentGroup(NULL); $form->addSubmit('ok', '(3/3) ' . __('Complete order »')); $form['ok']->setRendered(TRUE); $form->onSubmit[] = array($this, 'onDataFormSubmit'); // defaults if (isset(Environment::getSession(SESSION_ORDER_NS)->data)) { $form->setDefaults(Environment::getSession(SESSION_ORDER_NS)->data); } break; default: parent::createComponent($name); } }
/** * Component factory. * @see Nette/ComponentContainer#createComponent() */ protected function createComponentForm($name) { $form = new AppForm(); $form->addGroup('general'); //$form->getElementPrototype()->id('editform'); $form->addText('name', 'Křestí a příp. prostřední jméno')->addRule(Form::FILLED, "Jméno je potřeba vyplnit"); $form->addText('surname', 'Příjmení')->addRule(Form::FILLED, "Příjmení je potřeba vyplnit"); $form->addCheckbox('r', 'Osmileté gymnázium (R)'); $form->addSelect('mark', 'Písmeno třídy', array("A" => "A", "B" => "B", "C" => "C", "D" => "D")); $form->addGroup('left'); $form->addText('class', 'Maturitní ročník', 4); $form->addGroup('right'); $form->addSelect('number', 'Číslo třídy', array("?", "1", "2", "3", "4", "5", "6", "7", "8")); $form['class']->addConditionOn($form['number'], Form::EQUAL, 0)->addRule(Form::FILLED, 'Pokud nevyberete číslo třídy, musíte zadat maturitní ročník')->addRule(Form::NUMERIC, 'Ročník musí být číslo')->addRule(Form::RANGE, 'Rok maturity musí být od %d do %d', array(1960, 2999)); $form->addGroup('submit'); $form->addSubmit('ok', 'Přidat autora')->onClick[] = array($this, 'addClicked'); if ($this->setId != '') { $dataSource = dibi::query('SELECT * FROM [authors] WHERE authorId=%i', $this->setId)->fetch(); $form->setDefaults($dataSource); $form['ok']->onClick = array(array($this, 'SaveClicked')); $form['ok']->caption = "Uložit autora"; $form->addHidden("authorId")->setValue($this->setId); } $this->addComponent($form, $name); return; }
private function formNewEditFields(AppForm $form) { $form->addGroup('Content')->setOption('container', Html::el('fieldset')->id('contents')); $form->addText('title', 'Title')->addRule(Form::FILLED, 'Fill title'); $form->addTextarea('content', 'Text'); $templates = $this->model('contentTemplates')->get('page'); $form->addGroup('Properties')->setOption('container', Html::el('fieldset')->id('properties')); $categories = $this->model('categories')->getPairs(); $categories = array('0' => 'none') + $categories; $form->addSelect('category', 'Category', $categories); $form->addCheckBox('homepage', 'Set as homepage?'); $form->addSelect('template', 'Template', $templates); $form->addCheckBox('has_widgets', 'Has widgets'); $form->addText('publish_time', 'Publish time'); //$form->addText('time', ''); $form->addText('keywords', 'keywords'); $form->addTextarea('description', 'description'); $form->addHidden('content_type')->setValue('page'); if ($form->name == 'formNewPage') { //$form->addGroup('Link')->setOption('container', Html::el('fieldset')->id('link')); $menus = $this->model('menu')->getPairs(); $menus = array(0 => 'none') + $menus; $form->addSelect('link', 'Link in menu', $menus); } $form->addTextArea('css_files', 'Css files')->getControlPrototype()->{'data-ext'} = 'css'; $form->addTextArea('js_files', 'Js files')->getControlPrototype()->{'data-ext'} = 'js'; $form->addGroup('')->setOption('container', Html::el('fieldset')->id('buttons')); $form->addButton('btnClose', 'Close'); $form->addSubmit('btnPreview', 'Preview')->onClick[] = array($this, 'formNewPagePreview'); $form['btnPreview']->getControlPrototype()->class('ajax'); return $form; }
private function addPermissionCheckboxes(AppForm $form, $all_actions, $allowed_actions) { $actions = array(); foreach ($all_actions as $row) { $actions[$row->privilege][] = array('resource' => $row->resource, 'id' => $row->id); } foreach ($actions as $privilege => $resources) { $privilege = str_replace('_', ':', $privilege); $privilege = str_replace('presenter', '', $privilege); $form->addGroup($privilege, true); foreach ($resources as $resource) { $form->addCheckbox('allowed_' . $resource['id'], $resource['resource']); } } return $form; }