private function exampleForm() { $countries = array('Select your country', 'Europe' => array('CZ' => 'Czech Republic', 'FR' => 'France', 'DE' => 'Germany', 'GR' => 'Greece', 'HU' => 'Hungary', 'IE' => 'Ireland', 'IT' => 'Italy', 'NL' => 'Netherlands', 'PL' => 'Poland', 'SK' => 'Slovakia', 'ES' => 'Spain', 'CH' => 'Switzerland', 'UA' => 'Ukraine', 'GB' => 'United Kingdom'), 'AU' => 'Australia', 'CA' => 'Canada', 'EG' => 'Egypt', 'JP' => 'Japan', 'US' => 'United States', '?' => 'other'); $sex = array('m' => 'male', 'f' => 'female'); // Step 1: Define form with validation rules $form = new Form(); // group Personal data $form->addGroup('Personal data')->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.'); $form->addText('name', 'Your name:', 35)->addRule(Form::FILLED, 'Enter your name'); $form->addText('age', 'Your age:', 5)->addRule(Form::FILLED, 'Enter your age')->addRule(Form::INTEGER, 'Age must be numeric value')->addRule(Form::RANGE, 'Age must be in range from %.2f to %.2f', array(9.9, 100)); $form->addRadioList('gender', 'Your gender:', $sex); $form->addText('email', 'E-mail:', 35)->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:', 35); $form->addText('city', 'City:', 35)->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:'******'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')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']); $form->addFile('avatar', 'Picture:')->addCondition(Form::FILLED)->addRule(Form::MIME_TYPE, 'Uploaded file is not image', 'image/*'); $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()) { 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); } return $form; }
public function actionDefault($backlink) { $this->backlink = $backlink; $this->form = new AppForm($this, 'login'); $this->form->addText('userName', 'Uživatelské jméno:')->addRule(Form::FILLED, 'Uživatelské jméno musí být vyplněno.'); $this->form->addPassword('password', 'Přístupové heslo:')->addRule(Form::FILLED, 'Přístupové heslo musí být vyplněno.'); //->addRule(Form::MIN_LENGTH, 'Heslo musí být minimálně %d znaků', 12); $this->form->addSubmit('login', 'Přihlásit'); $this->form->onSubmit[] = array($this, 'FormSubmitted'); $this->template->form = $this->form; if (!isset($this->template->result)) { $this->template->result = ""; } $this->user->setAuthenticationHandler(new UsersModel()); }
private function loginForm() { $form = new Form(); $form->setAction(Lib_Link::build('login/login')); $form->addText('userLogin', 'Jmeno:', 10)->addRule(Form::FILLED, 'Vloz svoje uzivatelske jmeno.'); $form->addPassword('userPassword', 'Heslo:', 10)->addRule(Form::FILLED, 'Vloz tvoje heslo.')->addRule(Form::MIN_LENGTH, 'Heslo musi byt dlouhe minimalne %d znaku.', 3); $form->addSubmit('login', 'Prihlasit'); return $form . ''; }
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\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', 'send' => 'on',
function addItem_postInsertion() { /* controllare reload */ $mail = new Template("dtml/user.mail"); $mail->setContent("name", $_REQUEST['name']); $mail->setContent("username", $_REQUEST['username']); $mail->setContent("password", $_REQUEST['password']); $mail->setContent("message", $_REQUEST['message']); mail("{$_REQUEST['email']}", "{$GLOBALS['config']['website']['name']} Login data", $mail->get(), "From: {{$GLOBALS['config']['website']['email']}}"); } } /* LOCAL END */ #if (isset($_SESSION['registered-user'])) { # $main = new Template("dtml_{$_SESSION['language']}/frame-public-2.html"); #} else { # $main = new Template("dtml/frame-private.html"); #} $main = new Skin(); $form = new Form("dataEntry", $usersEntity); $form->addSection("Modifica Password"); #$form1->addText("username", "username", 20, MANDATORY); #$form1->addSection("personal data"); $form->addPassword("password", aux::lingual("Nuova Password", "New Password", "Nuova Password")); if (!isset($_REQUEST['page'])) { $_REQUEST['page'] = 1; $_REQUEST['value'] = $_SESSION['user']['username']; } $main->setContent("body", $form->editItem(NO_DELETE)); $main->close(); ?>
function lostPasswordChangeAction() { if (($user = core::$sql->row('id, password', DB . 'user', 'id=' . core::$sql->i(request_int('id', true)) . ' and id<>' . core::$sql->i(User::ANONIMOUS) . ' and is_disabled=0')) === false) { out(); } if (($hash = core::$user->getHash(core::$config['user']['lost_password_salt'], $user['password'])) != request_str('code', true)) { out(); } $html = ''; $errors = array(); $is_posted = request_int('is_posted'); $jump_to = 'lost_password_change_password'; if ($is_posted) { // $captcha_code = request_str('captcha_code'); if (!count($errors) && !request_str('password')) { $errors[] = s('Пожалуйста, укажите пароль.'); } if (!count($errors) && request_str('password') != request_str('password2')) { $errors[] = s('Введенные пароли не совпадают. Пожалуйста, попробуйте еще раз.'); } // if(captcha_compare(request_str('captcha_code'))) { // captcha_close(); if (!count($errors)) { $password_hash = core::$user->getHash(core::$config['user']['password_salt'], request_str('password')); core::$sql->update(array('password' => core::$sql->s($password_hash)), DB . 'user', 'id=' . core::$sql->i($user['id'])); core::$user->logout(); go(core::$config['http_home'] . 'lost_password/changed/'); } // } // else // $errors []= 'Неверный код подтверждения'; } $page = new PageCommon(s('Смена пароля')); $html .= $page->start(); $html .= '<div class="row"><div class="span4 offset4"><h2>' . s('Смена пароля') . '</h2>'; if (count($errors)) { $html .= '<div class="alert alert-danger"><p>' . escape($errors[0]) . '</p></div>'; } $form = new Form('lost_password_change', false, 'post'); $html .= '<div class="well">' . $form->start() . $form->addVariable('is_posted', 1) . $form->addVariable('id', request_int('id')) . $form->addVariable('code', request_str('code')) . $form->addPassword('password', s('Пароль'), '', array('is_required' => true)) . $form->addPassword('password2', s('Подтверждение пароля'), '', array('is_required' => true)) . $form->submit(s('Сохранить')) . '</div>'; /* $html .= '<ul> <li><a href="' .core::$config['http_home'] . 'login/">' . s('Вход для зарегистрированных') . '</a></li> </ul>'; */ $html .= '<script> $(document).ready(function() { $("#' . $jump_to . '").focus(); }); </script>'; $html .= '</div></div>'; $html .= $page->stop(); return $html; }
/*use Nette\Forms\Form;*/ /*use Nette\Debug;*/ Debug::enable(); $countries = array('Select your country', 'Europe' => array('CZ' => 'Czech Republic', 'FR' => 'France', 'DE' => 'Germany', 'GR' => 'Greece', 'HU' => 'Hungary', 'IE' => 'Ireland', 'IT' => 'Italy', 'NL' => 'Netherlands', 'PL' => 'Poland', 'SK' => 'Slovakia', 'ES' => 'Spain', 'CH' => 'Switzerland', 'UA' => 'Ukraine', 'GB' => 'United Kingdom'), 'AU' => 'Australia', 'CA' => 'Canada', 'EG' => 'Egypt', 'JP' => 'Japan', 'US' => 'United States', '?' => 'other'); $sex = array('m' => 'male', 'f' => 'female'); // Step 1: Define form $form = new Form(); $form->addText('name', 'Your name:', 35); $form->addText('age', 'Your age:', 5); $form->addRadioList('gender', 'Your gender:', $sex); $form->addText('email', 'E-mail:', 35)->setEmptyValue('@'); $form->addCheckbox('send', 'Ship to address'); $form->addText('street', 'Street:', 35); $form->addText('city', 'City:', 35); $form->addSelect('country', 'Country:', $countries)->skipFirst(); $form->addPassword('password', 'Choose password:'******'password2', 'Reenter password:'******'avatar', 'Picture:'); $form->addHidden('userid'); $form->addTextArea('note', 'Comment:', 30, 5); $form->addSubmit('submit1', 'Send'); // 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... $form['send']->addCondition(Form::EQUAL, TRUE)->toggle('sendBox');
$form->addText('age', 'Your age:', 5)->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->addRadioList('gender', 'Your gender:', $sex); $form->addText('email', 'E-mail:', 35)->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:', 35); $form->addText('city', 'City:', 35)->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:'******'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')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']); $form->addFile('avatar', 'Picture:'); $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()) { echo '<h2>Form was submitted and successfully validated</h2>'; $values = $form->getValues(); Debug::dump($values); // this is the end, my friend :-)
function addItem_postInsertion() { /* controllare reload */ $mail = new Template(Settings::getSkin() . "/user.mail"); $mail->setContent("name", $_REQUEST['name']); $mail->setContent("username", $_REQUEST['username']); $mail->setContent("password", $_REQUEST['password']); $mail->setContent("message", $_REQUEST['message']); mail("{$_REQUEST['email']}", "{Config::getInstance()->getConfigurations()['website']['name']} Login data", $mail->get(), "From: {{Config::getInstance()->getConfigurations()['website']['email']}}"); } } /* LOCAL END */ #if (isset($_SESSION['registered-user'])) { # $main = new Template("dtml_{$_SESSION['language']}/frame-public-2.html"); #} else { # $main = new Template("dtml/frame-private.html"); #} $main = new Skin(); $form = new Form("dataEntry", $usersEntity); $form->addSection("Modifica Password"); #$form1->addText("username", "username", 20, MANDATORY); #$form1->addSection("personal data"); $form->addPassword("password", Parser::lingual("Nuova Password", "New Password", "Nuova Password")); if (!isset($_REQUEST['page'])) { $_REQUEST['page'] = 1; $_REQUEST['value'] = $_SESSION['user']['username']; } $main->setContent("body", $form->editItem(NO_DELETE)); $main->close(); ?>
<?php session_start(); require "include/template2.inc.php"; require "include/beContent.inc.php"; require "include/content.inc.php"; require "include/auth.inc.php"; $main = new Skin(); $form = new Form("dataEntry", $usersEntity); switch ($_REQUEST['section']) { case "password": $form->addSection("Password"); $form->addPassword("password", "New password", 20, MANDATORY); $form->addPassword("password2", "Confirm password", 20, MANDATORY); $form->addValidation("password", "password2", EQUAL, "The passwords do not match!"); break; case "foto": $form->addSection("Foto"); $form->addFile("foto", "Foto"); break; default: $form->addSection("Your Profile"); $form->addText("username", "Username"); $form->addText("email", "Email", 50, MANDATORY); $form->addText("name", "Name", 40, MANDATORY); $form->addText("surname", "Surname", 40, MANDATORY); $form->addText("phone", "Phone", 20, MANDATORY); $form->addText("fax", "Fax", 20, MANDATORY); $form->addFile("foto", "Foto"); $form->addCheck("Newsletter", ":active_newsletter:*:CHECKED"); $form->addSection("Password");