public function testNoTranslate() { $form = new Form(); $form->setTranslator(new MultiSelectMockTranslator()); $form->addMultiSelect('translateFalse', 'label', ['a', 'b', 'c'])->setTranslate(FALSE); $form->addMultiSelect('translate', 'label', ['a', 'b', 'c'])->setTranslate(TRUE); // Translate false $form['translateFalse']->getLabel(); $form['translateFalse']->getControl(); $this->assertSame(['label'], MultiSelectMockTranslator::$toTranslate); MultiSelectMockTranslator::$toTranslate = []; // Translate $form['translate']->getLabel(); $form['translate']->getControl(); $this->assertSame(['label', 'a', 'b', 'c'], MultiSelectMockTranslator::$toTranslate); MultiSelectMockTranslator::$toTranslate = []; }
public function actionUserChange($akce = 0, $id = -1) { $this->access($id); //kvůli Nette - action je vyhrazeno $action = $akce; $this->verifyUser(); $this->form = new AppForm($this, 'userChange'); //TODO: Definovat zprávu //$this->form->addProtection($this->formProtectedMessage); $msg = 'Heslo musí obsahovat VELKÁ a malá písmena a číslice!'; $this->form->addGroup('Přihlašovací informace'); $this->form->addText('userName', 'Uživatelské jméno:')->addRule(Form::FILLED, 'Uživatelské jméno musí být vyplněno.')->addRule(Form::MIN_LENGTH, 'Uživatelské jméno musí mít alespoň %d znaky.', 4)->addRule(Form::MAX_LENGTH, 'Uživatelské jméno může mít nejvýše %d znaků.', 20); if ($action > 0) { $this->form['userName']->setDisabled(true); } if ($action != 1) { $this->form->addPassword('password1', 'Heslo:')->addRule(Form::FILLED, 'Heslo musí být vyplněno.')->addRule(Form::MIN_LENGTH, 'Heslo musí mít alespoň %d znaků.', 8)->addRule(Form::MAX_LENGTH, 'Heslo může mít nejvýše %d znaků', 50)->addRule(Form::REGEXP, $msg, '/[A-Z]+/')->addRule(Form::REGEXP, $msg, '/[a-z]+/')->addRule(Form::REGEXP, $msg, '/[0-9]+/'); $this->form->addPassword('password2', 'Přístupové heslo (pro kontrolu):')->addRule(Form::EQUAL, 'Zadaná hesla se neshodují.', $this->form['password1']); $this->form->addText('navrhHesla', 'Navrhované heslo:'); } if ($action < 2) { $this->form->addGroup('Osobní informace'); $this->form->addText('firstName', 'Jméno:')->addRule(Form::FILLED, 'Jméno musí být vyplněno.'); $this->form->addText('surname', 'Přijmení:')->addRule(Form::FILLED, 'Přijmení musí být vyplněno.'); $this->form->addText('title', 'Titul:')->addRule(Form::MAX_LENGTH, 'Titul může mít nejvýše %d znaků.', 10); $this->form->addGroup('Kontaktní informace'); $this->form->addText('email', 'E-mail:')->addRule(Form::FILLED, 'E-mail musí být vyplněn.')->addRule(Form::EMAIL, 'Zadaný e-mail není platný.'); $this->form->addText('icq', 'ICQ:')->addCondition(Form::FILLED)->addRule(Form::NUMERIC, 'ICQ musí být číslo.')->addRule(Form::MAX_LENGTH, 'ICQ může mít nejvýše %d znaků.', 10); $this->form->addText('skype', 'Skype:')->addRule(Form::MAX_LENGTH, 'Skype může mát nejvýše %d znaků.', 50); $this->form->addText('mobile', 'Mobilní telefon:')->addCondition(Form::FILLED)->addRule(Form::NUMERIC, 'Mobilní telefon musí být číslo.')->addRule(Form::MAX_LENGTH, 'Mobilní telefon může mít nejvýše %d znaků.', 20); $roles = UsersModel::getRoles(); // Zobrazujeme pouze tehdy je-li uživatel administrátor - aby si uživatel sám nemohl měnit skupinu if ($this->user->isInRole('Administrator')) { $this->form->addGroup('Přístupová práva (může být vybráno více skupin)'); $this->form->addMultiSelect('prava', 'Přístupová práva:', $roles, 2); } } $this->form->onSubmit[] = array($this, 'UserFormSubmitted'); $this->form->addHidden('action')->setValue($action); if ($action > 0) { $data = UsersModel::getUser($id); $data['navrhHesla'] = UsersModel::genPass(); // Nastavíme výchozí hodnoty pro formulář $this->form->setDefaults($data); $this->form->addHidden('id')->setValue($id); $this->form->addSubmit('ok', 'Aktualizovat'); // ->onClick[] = array($this, 'OkClicked'); // nebo 'OkClickHandler' } else { $data['navrhHesla'] = UsersModel::genPass(); // Nastavíme výchozí hodnoty pro formulář $this->form->setDefaults($data); $this->form->addSubmit('ok', 'Vytvořit'); // ->onClick[] = array($this, 'OkClicked'); // nebo 'OkClickHandler' } $this->template->form = $this->form; }
/*use Nette\Forms\Form;*/ /*use Nette\Forms\TextInput;*/ /*use Nette\Forms\FormContainer;*/ /*use Nette\Environment;*/ /*use Nette\Debug;*/ Debug::enable(); $countries = array('Select your country', 'Europe' => array(1 => 'Czech Republic', 2 => 'Slovakia'), 3 => 'USA', 4 => 'other'); $sex = array('m' => 'male', 'f' => 'female'); $form = new Form(); $form->addText('name', 'Your name:', 35); // item name, label, size, maxlength $form->addTextArea('note', 'Comment:', 30, 5); $form->addRadioList('gender', 'Your gender:', $sex); $form->addCheckbox('send', 'Ship to address'); $form->addSelect('country', 'Country:', $countries)->skipFirst(); $form->addMultiSelect('countrym', 'Country:', $countries); $form->addPassword('password', 'Choose password:'******'avatar', 'Picture:'); $form->addHidden('userid'); $sub = $form->addContainer('firstperson'); $sub->addText('age', 'Your age:', 5); $sub = $form->addContainer('secondperson'); $sub->addText('age', 'Your age:', 5); $sub->addFile('avatar', 'Picture:'); $form->addSubmit('submit1', 'Send'); $_SERVER['REQUEST_METHOD'] = 'POST'; /* valid data $_POST = array( 'name' => 'string', 'note' => 'textbox', 'gender' => 'm',
* * - custom charset encoding (Forms internally works in UTF-8 encoding!) */ require '../../Nette/loader.php'; /*use Nette\Forms\Form;*/ /*use Nette\Debug;*/ /*use Nette\Web\Html;*/ Debug::enable(); $countries = array('Select your country', 'Europe' => array('CZ' => 'Česká republika', 'SK' => 'Slovakia'), 'AU' => 'Australia', 'CA' => 'Canada', 'EG' => 'Egypt', 'JP' => 'Japan', 'US' => 'United States', '?' => 'other'); // Step 1: Define form with validation rules $form = new Form(); $form->encoding = 'ISO-8859-1'; // group Personal data $form->addGroup('Personal data'); $form->addText('name', 'Your name:', 35); $form->addMultiSelect('country', 'Country:')->skipFirst()->setItems($countries, FALSE); $form->addHidden('userid'); $form->addTextArea('note', 'Comment:', 30, 5); // group for buttons $form->addGroup(); $form->addSubmit('submit1', 'Send'); // Step 2: Check if form was submitted? if ($form->isSubmitted()) { // Step 2c: Check if form is valid if ($form->isValid()) { header('Content-type: text/html; charset=utf-8'); echo '<h2>Form was submitted and successfully validated</h2>'; $values = $form->getValues(); Debug::dump($values); // this is the end, my friend :-) if (empty($disableExit)) {