Advertisement
weacom

Class Form

Sep 4th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Auth\Form;
  4.  
  5. use \Phalcon\Forms\Form;
  6. use Phalcon\Forms\Element\Text,
  7.     Phalcon\Forms\Element\Select,
  8.     Phalcon\Forms\Element\Password,
  9.     Phalcon\Forms\Element\Submit,
  10.     Phalcon\Forms\Element\Check,
  11.     Phalcon\Forms\Element\Hidden,
  12.     Phalcon\Forms\Element\Date;
  13.  
  14. use Phalcon\Validation\Validator\Identical;
  15.  
  16. class LoginForm extends Form
  17. {
  18.     /**
  19.      * Этот метод возвращает значение по умолчанию для поля 'csrf'
  20.      */
  21.     public function getCsrf()
  22.     {
  23.         return $this->security->getSessionToken();
  24.     }
  25.     /**
  26.      * Инициализация эллеметов формы
  27.      * описание всех эллементов полей и кнопок
  28.      */
  29.     public function initialize($entity = null, $options = null){
  30.  
  31.         // Установка сущности
  32.         $this->setEntity($this);
  33.  
  34.         // Логин пользователя
  35.         $login = new Text('login', array(
  36.             'placeholder' => 'Введите ваш логин',
  37.             'autocomplete' => 'off'
  38.         ));
  39.         $login->setLabel('Имя пользователя:');
  40.  
  41.         $this->add($login);
  42.  
  43.         // Пароль
  44.         $password = new Password('password', array(
  45.             'placeholder' => 'Введите ваш пароль',
  46.             'autocomplete' => 'off'
  47.         ));
  48.         $password->setLabel('Ваш пароль:');
  49.         $this->add($password);
  50.  
  51.         // Кнопка войти
  52.         $submit = new Submit('button', array(
  53.             'value' => 'Войти'
  54.         ));
  55.         $this->add($submit);
  56.  
  57.         // Запомнить меня
  58.         $remember = new Check('remember', array(
  59.             'value' => 1,
  60.             'checked'=> true
  61.         ));
  62.         $remember->setLabel('Запомнить меня');
  63.         $this->add($remember);
  64.  
  65.         // Csrf token
  66.         $csrf = new Hidden('csrf_token', array(
  67.             'value' => $this->getCsrf()
  68.         ));
  69.         $csrf->addValidator(
  70.             new Identical(array(
  71.                 'value' => $this->getCsrf(),
  72.                 'message' => 'Произошла ошибка "csrf-token" не корректный, обновите окно браузера'
  73.             ))
  74.         );
  75.         $this->add($csrf);
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement