Example #1
0
 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;
 }
Example #2
0
 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());
 }
Example #3
0
 protected function createComponentForm()
 {
     $form = new Form();
     $form->addText('title', 'Titulek', 80)->addRule(Form::FILLED, 'Vyplňte prosím titulek!');
     $form->addTextarea('text', 'Text', 50, 20)->addRule(Form::FILLED, 'Vyplňte prosím text článku!')->getControlPrototype()->setClass('wysiwyg');
     $form->addSubmit('ok', 'Upravit')->getControlPrototype()->data['confirm'] = "Opravdu chcete upravit tento clanek?";
     $form->onSuccess[] = callback($this, 'process');
     return $form;
 }
Example #4
0
 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 . '';
 }
Example #5
0
 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;
 }
Example #6
0
    function defaultAction()
    {
        $subjects = array(1 => array('id' => 1, 'title' => s('General question')), 2 => array('id' => 2, 'title' => s('Bug report')), 3 => array('id' => 3, 'title' => s('Collaboration or partership')), 4 => array('id' => 4, 'title' => s('Idea')), 5 => array('id' => 5, 'title' => s('Other')));
        $html = '';
        $errors = array();
        $is_posted = request_int('is_posted');
        $jump_to = 'feedback_name';
        if ($is_posted) {
            if (!count($errors) && !request_str('email')) {
                $errors[] = s('Please, enter your email');
                $jump_to = 'feedback_email';
            }
            if (!count($errors) && request_str('email') && !filter_var(request_str('email'), FILTER_VALIDATE_EMAIL)) {
                $errors[] = s('Please, provide correct email address. For example: john@gmail.com');
                $jump_to = 'feedback_email';
            }
            if (!count($errors) && !request_str('message')) {
                $errors[] = s('Enter the message.');
                $jump_to = 'feedback_password';
            }
            if (!count($errors)) {
                $data = array('{name}' => request_str('name'), '{email}' => request_str('email'), '{subject}' => $subjects[request_int('subject_id')]['title'], '{message}' => request_str('message'));
                $message = str_replace(array_keys($data), array_values($data), 'Name: {name}
Email: {email}

Subject: {subject}

{message}


' . $_SERVER['REMOTE_ADDR'] . ' ' . date('r'));
                core::$sql->insert(array('message' => core::$sql->s($message), 'insert_stamp' => core::$sql->i(time())), DB . 'feedback');
                require_once '../mod/lib.mail.php';
                foreach (array('*****@*****.**') as $email) {
                    mail_send(request_str('name'), request_str('email'), $email, 'Metro4all.org - ' . $subjects[request_int('subject_id')]['title'], $message, false);
                }
                go(Core::$config['http_home'] . 'feedback/?action=ok');
            }
        }
        $page = new PageCommon(s('Feedback'));
        $html .= $page->start();
        $html .= '<div class="row"><div class="col-md-offset-2 col-md-8"><h2>' . s('Feedback') . '</h2>';
        if (count($errors)) {
            $html .= '<div class="alert alert-danger"><p>' . escape($errors[0]) . '</p></div>';
        }
        $form = new Form('feedback', false, 'post');
        $html .= '<div class="well">' . $form->start() . $form->addVariable('is_posted', 1) . $form->addString('name', s('Name'), $is_posted ? request_str('name') : '') . $form->addString('email', s('E-mail'), $is_posted ? request_str('email') : '', array('is_required' => true)) . $form->addSelect('subject_id', s('Subject'), $is_posted ? request_int('subject_id') : 1, array('data' => $subjects)) . $form->addText('message', s('Message'), $is_posted ? request_str('message') : '', array('is_required' => true, 'style' => 'height:200px')) . $form->submit(s('Send')) . '</div>';
        $html .= '<script> $(document).ready(function() { $("#' . $jump_to . '").focus(); }); </script>';
        $html .= '</div></div>';
        $html .= $page->stop();
        return $html;
    }
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("dataEntry", $layerEntity);
$form->addSection("Layer Management");
$form->addText("title", "Title", 40, MANDATORY);
$form->addText("subtitle", "Subtitle", 40, MANDATORY);
$form->addEditor("description", "Text", 10, 50);
$form->addFile("foto", "Foto");
$form->addSelectFromReference2($bgEntity, "bg_id", "Background");
$form->addSelectFromReference2($pageEntity, "page_id", "Page");
$form->addPosition("position", "Order", "title");
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("albumform", $albumEntity);
$form->addSection("Album Management");
$form->addText("title", "Album Name", 40, MANDATORY);
$form->addEditor("description", "Album Description", 10, 100);
$form->addPosition("position", "Order", "title");
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin("default");
$form = new Form("dataEntry", $contattiEntity);
$form->addSection("Contact Management");
$form->addText("email", "email", 100, MANDATORY);
$form->addFile("Photo", "Foto");
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case 'add':
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
Example #10
0
/**
 * Nette\Forms example 1
 *
 * - separated form and rules definition
 * - manual form rendering
 */
require '../../Nette/loader.php';
/*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');
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("dataEntry", $servicesEntity, POST);
$form->addSection("Service Management");
$form->addText("name", "Name", 40, MANDATORY);
$form->addText("script", "Script", 60, MANDATORY);
$form->addEditor("des", "Description", 15, 40);
//$form->addFile("icon", "Icon");
$form->addSection("Menu");
$form->addText("entry", "Menu Entry", 40, MANDATORY);
$form->addSelectFromReference2($servicecategoryEntity, "servicecategory", "Category");
$form->addHierarchicalPosition("position", "Position", "name", "servicecategory");
$form->addCheck("Visible", ":visible:*:*");
$form->addSection("Data filtering");
$form->addSelectFromReference2($entitiesEntity, "id_entities", "Entity");
$form->restrictReference("id_entities", "owner = '1' or name = '{$usersEntity->name}' or name = '{$logEntity->name}'");
$form->addSelectFromReference2($groupsEntity, "superuser_group", "Superuser Group");
$form_groups = new Form("dataEntry2", $servicesGroupsRelation);
$form->addSection("Groups");
$form_groups->addRelationManager("groups", "Groups");
$form->triggers($form_groups);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("dataEntry", $channelEntity);
$form->addSection("Picture Management");
$form->addText("title", "Title", 50, MANDATORY);
$form->addTextarea("description", "Description", 2, 100);
$form->addSelectFromReference2($albumEntity, "title_album", "Select Album", 100);
$form->addSelectFromReference2($usersEntity, "username_users", "Username", 100);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
Example #13
0
 public function echoClientEdit()
 {
     $id;
     $contact_id;
     $sex = 'm';
     $first_name;
     $middle_name;
     $last_name;
     $suffix;
     $ssn;
     $dob;
     $aka;
     $dba;
     $success = true;
     if ($this->page_type == 'edit') {
         $sth = $this->db->prepare("SELECT `contact_id`,`contacts`.`name` AS 'last_name'," . "`first_name`,`middle_name`,`suffix`,`sex`,`ssn`,`aka`,`dba`, " . "DATE_FORMAT(`dob`, '%c-%e-%Y') AS 'dob_format' " . 'FROM `clients` ' . 'JOIN `contacts` ON `clients`.`contact_id`=`contacts`.`id` ' . 'WHERE `clients`.`id`=?');
         $sth->execute(array($this->id));
         if ($row = $sth->fetch()) {
             $id = $this->id;
             $contact_id = $row['contact_id'];
             $first_name = $row['first_name'];
             $middle_name = $row['middle_name'];
             $last_name = $row['last_name'];
             $suffix = $row['suffix'];
             $sex = $row['sex'] ? $row['sex'] : 'none';
             $ssn = $row['ssn'];
             $dob = $row['dob_format'];
             $aka = $row['aka'];
             $dba = $row['dba'];
         } else {
             $success = false;
         }
     }
     if ($success) {
         $form = new Form('client');
         $form->addHeading('Name');
         $form->addSelect('', 'sex', array('m' => 'Male', 'f' => 'Female', 'none' => 'None'), $sex);
         $form->addText('First name:', 'first_name', false, $first_name);
         $form->addText('Middle:', 'middle_name', false, $middle_name);
         $form->addText('Last (or biz name):', 'name', true, $last_name);
         $form->addText('Suffix (Jr/Sr/etc):', 'suffix', false, $suffix);
         $form->addHeading('Info');
         $form->addDate('Date of birth:', 'dob', false, true, $dob);
         $form->addText('SSN (no dashes):', 'ssn', false, $ssn, 'minlength="9" maxlength="9" digits="true"');
         $form->addText('AKA:', 'aka', false, $aka);
         $form->addText('DBA:', 'dba', false, $dba);
         $form->addHidden('id', $id);
         $form->addHidden('contact_id', $contact_id);
         if ($this->admin && $this->page_type == 'edit') {
             $form->addDelete();
         }
         $form->echoForm();
     }
 }
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("dataEntry", $catModuleEntity);
$form->addSection("Module Category Management");
$form->addText("name", "Name", 40, MANDATORY);
$form->addPosition("position", "Order", "name");
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("dataEntry", $testEntity);
$form->addSection("Testimonial Management");
$form->addText("name", "Name", 60, MANDATORY);
$form->addPosition("posizione", "Posizione", "name");
$form->addText("edizione", "Edizione", 20, MANDATORY);
$form->addText("affiliazione", "Affiliazione", 60, MANDATORY);
$form->addFile("photo", "Foto");
$form->addTextarea("messaggio", "Messaggio", 10, 60);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
Example #16
0
 public function echoFolderEdit()
 {
     $success = true;
     $name;
     $id;
     if ($this->page_type == 'edit') {
         $sth = $this->db->prepare("SELECT `name` " . 'FROM `folders` WHERE `id`=?');
         $sth->execute(array($this->id));
         if ($row = $sth->fetch()) {
             $id = $this->id;
             $name = $row['name'];
         } else {
             $success = false;
         }
     }
     if ($success) {
         $form = new Form('folder');
         $form->addText('Folder name:', 'name', true, $name);
         $form->addHidden('id', $id);
         $form->addHidden('folder_id', $this->parent_folder_id);
         if ($this->page_type == 'edit' && ($this->admin || $this->emp_id == $this->folder_emp_id || $this->office_admin && $this->folder_office_id == $this->office_id)) {
             $move_arr = $this->moveFolderArr($this->parent_folder_id, $this->id);
             if (count($move_arr) > 1) {
                 //$form->addHeading('Move');
                 $form->addSelect('Move to:', 'move', $move_arr);
             }
             $form->addDelete();
         }
         $form->echoForm();
     }
 }
Example #17
0
<h1>Nette\Forms example 1</h1>

<?php 
require_once '../../Nette/loader.php';
/*use Nette\Forms\Form;*/
/*use Nette\Debug;*/
Debug::enable();
// ******* DEFINE FORM
$form = new Form();
$form->addText('name', 'Your name:');
$form->addText('age', 'Your age:', 5);
$form->addFile('avatar', 'Picture:');
$form->addSubmit('submit1', 'Send');
// define form rules
$form['age']->addRule(Form::RANGE, 'Age must be in range from %.2f to %.2f', array(9.9, 100));
$form['avatar']->addRule(Form::MIME_TYPE, 'Avatar must be image', 'image/*');
$form['avatar']->addError('User error');
$form['avatar']->addError(Html::el('strong', 'User error #2'));
echo $form;
<?php

session_start();
require 'include/beContent.inc.php';
require_once 'include/content.inc.php';
require 'include/auth.inc.php';
require_once realpath(dirname(__FILE__)) . '/include/view/template/InitGraphic.php';
$main = new Skin('system');
InitGraphic::getInstance()->createSystemGraphic($main);
$form = new Form('dataEntry', $pageEntity);
$form->addSection('Page Management');
$form->addText('title', 'Titolo', 60, null, 60, true);
//$form->addTextarea('description', 'Description', 10, 50);
$form->addText('subtitle', 'Sottotitolo', 60);
$form->addText('link', 'Script Collegato', 255);
$form->addEditor('body', 'Corpo', 50, 50);
$form->addSelectFromReference($pageEntity, 'father', 'Padre');
//$form->addHierarchicalPosition('section', 'Sezione padre',MANDATORY,$sectionEntity);
$imageForm = new ImageForm('imageEntry', $pageEntity);
$imageForm->addImage('foto', 'Foto');
$form->triggers($imageForm);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = 'edit';
}
$main->setContent('body', $form->requestAction());
$main->close();
Example #19
0
<h1>Nette\Forms user validator test</h1>

<?php 
require_once '../../Nette/loader.php';
/*use Nette\Forms\Form;*/
/*use Nette\Debug;*/
Debug::enable();
function myValidator1($item, $arg)
{
    return $item->getValue() != $arg;
}
$form = new Form();
$form->addText('name', 'Text:', 10)->addRule('myValidator1', 'Value %d is not allowed!', 11)->addRule(~'myValidator1', 'Value %d is required!', 22);
$form->addSubmit('submit1', 'Send');
// was form submitted?
if ($form->isSubmitted()) {
    echo '<h2>Submitted</h2>';
    // check validation
    if ($form->isValid()) {
        echo '<h2>And successfully validated!</h2>';
        $values = $form->getValues();
        Debug::dump($values);
        // this is the end :-)
        exit;
    }
} else {
    // not submitted?
    // so define default values
    $defaults = array();
    $form->setDefaults($defaults);
}
<?php

session_start();
require "include/beContent.inc.php";
require "include/auth.inc.php";
require_once 'include/content.inc.php';
require_once realpath(dirname(__FILE__)) . '/include/view/template/InitGraphic.php';
$main = new Skin("system");
InitGraphic::getInstance()->createSystemGraphic($main);
$form = new Form("dataEntry", $sliderEntity);
$form->addTitleForm("Slider Management");
$form->addSection('slider details');
$form->addText("titolo", "Titolo", 40, MANDATORY);
$form->addText("descrizione", "Descrizione", 40);
$form->addText("width", "Largezza", 40, MANDATORY);
$form->addText("height", "Altezza", 40);
$relationForm = new RelationForm("dataEntry3", $imageSliderRelation);
$relationForm->addSection('Immagini da legare');
$relationForm->addRelationManager("id_sys_image", "Immagine", LEFT);
$form->triggers($relationForm);
$relationPageForm = new RelationForm("dataEntry3", $sliderPageRelation);
$relationPageForm->addSection('Pagine da legare');
$relationPageForm->addRelationManager("id_sys_page", "Pagine");
$form->triggers($relationPageForm);
$main->setContent("body", $form->requestAction());
$main->close();
Example #21
0
 public function echoEmail()
 {
     $email;
     $alert = 0;
     $primary = 0;
     $success = true;
     if ($this->contact_item_id) {
         $sth = $this->db->prepare("SELECT `primary`,`alert`,`email` " . 'FROM `con_emails` ' . 'WHERE `con_emails`.`id`=?');
         $sth->execute(array($this->contact_item_id));
         if ($row = $sth->fetch()) {
             $email = $row['email'];
             $alert = $row['alert'];
             $primary = $row['primary'];
         } else {
             $success = false;
         }
     }
     if ($success) {
         $form = new Form('email');
         $form->addText('Email:', 'email', true, $email, 'email="true"');
         $form->addSwitch('Primary:', 'primary', array('0' => 'No', '1' => 'Yes'), $primary);
         $form->addSwitch('Receive alerts:', 'alert', array('0' => 'No', '1' => 'Yes'), $alert);
         $form->addHidden('id', $this->contact_item_id);
         $form->addHidden('contact_id', $this->contact_id);
         //$form->addHidden('callback', $this->form_callback);
         if ($this->contact_item_id) {
             $form->addDelete();
         }
         $form->echoForm();
     }
 }
Example #22
0
<?php

/**
 * Nette\Forms example 8
 *
 * - Cross-Site Request Forgery (CSRF) form protection
 */
require '../../Nette/loader.php';
/*use Nette\Forms\Form;*/
/*use Nette\Debug;*/
Debug::enable();
$form = new Form();
$form->addText('text', 'Any text:');
$form->addProtection('Security token did not match. Possible CSRF attack.', 3);
$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;
        }
    }
}
// Step 3: Render form
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("dataEntry", $tagEntity);
$form->addSection("Tag Management");
$form->addText("tag", "Tag", 40, MANDATORY);
$form->addText("text", "Search Text", 40, MANDATORY);
$form->addPosition("position", "Position", "tag");
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
$channelEntity = new Entity($database,"bc_channel");
$channelEntity->setPresentation("title");
$channelEntity->addField("title",VARCHAR,50,MANDATORY);
$channelEntity->addField("link",VARCHAR,100,MANDATORY);
$channelEntity->addField("description",VARCHAR,150,MANDATORY);
$channelEntity->addReference($lanEntity, "language");

$channelEntity->addField("image_title",VARCHAR,50);
$channelEntity->addField("image_link",VARCHAR,100);
$channelEntity->addField("image",FILE);

$channelEntity->connect();
*/
$form->addSection("Image Management");
$form->addText("image_title", "Title", 50);
$form->addFile("image", "Image");
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
<?php

/**
 * Created by PhpStorm.
 * User: SS
 * Date: 09/01/2016
 * Time: 14.57
 */
session_start();
require "include/beContent.inc.php";
require_once 'include/content.inc.php';
require "include/auth.inc.php";
require_once realpath(dirname(__FILE__)) . '/include/view/template/InitGraphic.php';
$main = new Skin("system");
InitGraphic::getInstance()->createSystemGraphic($main);
$form = new Form("dataEntry", $categoriaristoranteEntity);
$form->addSection("Categoria Ristorante Management");
$form->addText("nome", "Nome", 40, MANDATORY);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = 'edit';
}
$main->setContent("body", $form->requestAction());
$main->close();
Example #26
0
    public function translate($message, $count = NULL)
    {
        return parent::translate($message);
    }
}
$countries = array('Select your country', 'Europe' => array('CZ' => 'Czech Republic', 'SK' => 'Slovakia'), 'US' => 'USA', '?' => 'other');
$sex = array('m' => 'male', 'f' => 'female');
// Step 1: Define form with validation rules
$form = new Form();
// enable translator
$translator = new MyTranslator('gettext', dirname(__FILE__) . '/messages.mo', 'cs');
$translator->setLocale('cs');
$form->setTranslator($translator);
// group Personal data
$form->addGroup('Personal data');
$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 %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');
<?php

/**
 * Created by PhpStorm.
 * User: SS
 * Date: 09/01/2016
 * Time: 11.44
 */
session_start();
require "include/beContent.inc.php";
require_once 'include/content.inc.php';
require "include/auth.inc.php";
require_once realpath(dirname(__FILE__)) . '/include/view/template/InitGraphic.php';
$main = new Skin("system");
InitGraphic::getInstance()->createSystemGraphic($main);
$form = new Form("dataEntry", $gestionetavoliEntity);
$form->addSection("Tavoli");
$form->addText("n_sedie", "Numero sedie", 40, MANDATORY);
$form->addCheck("stato", "Occupato");
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = 'edit';
}
$main->setContent("body", $form->requestAction());
$main->close();
<?php

session_start();
require "include/template2.inc.php";
require "include/beContent.inc.php";
require "include/auth.inc.php";
$main = new Skin();
$form = new Form("dataEntry", $genEntity);
$form->addSection("Configurations Management");
$form->addText("name", "Name", 40, MANDATORY);
$form->addText("description", "Description", 60);
$form->addTextarea("metadata", "Metadata", 10, 80);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>
 
Example #29
0
<h1>Nette\Forms invalid HTTP data test</h1>

<?php 
require_once '../../Nette/loader.php';
/*use Nette\ComponentContainer;*/
/*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';
    {
    }
    function editItem_preUpdate()
    {
        $_REQUEST['metadata'] = json_encode($_REQUEST);
    }
    function addItem_postInsertion()
    {
        // boh
    }
}
$main = new Skin();
$form = new Form("dataEntry", $genEntity);
$form->addSection("Generics Management");
$form->AddText("name", "Name", 50, MANDATORY);
$form->AddText("description", "Description", 70);
$form->addText("metadata", "Metadata", 100, MANDATORY);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "edit";
}
switch ($_REQUEST['action']) {
    case "add":
        $main->setContent("body", $form->addItem());
        break;
    case "edit":
        $main->setContent("body", $form->editItem());
        break;
}
$main->close();
?>