Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Auth\Form;
- use \Phalcon\Forms\Form;
- use Phalcon\Forms\Element\Text,
- Phalcon\Forms\Element\Select,
- Phalcon\Forms\Element\Password,
- Phalcon\Forms\Element\Submit,
- Phalcon\Forms\Element\Check,
- Phalcon\Forms\Element\Hidden,
- Phalcon\Forms\Element\Date;
- use Phalcon\Validation\Validator\Identical;
- class LoginForm extends Form
- {
- /**
- * Этот метод возвращает значение по умолчанию для поля 'csrf'
- */
- public function getCsrf()
- {
- return $this->security->getSessionToken();
- }
- /**
- * Инициализация эллеметов формы
- * описание всех эллементов полей и кнопок
- */
- public function initialize($entity = null, $options = null){
- // Установка сущности
- $this->setEntity($this);
- // Логин пользователя
- $login = new Text('login', array(
- 'placeholder' => 'Введите ваш логин',
- 'autocomplete' => 'off'
- ));
- $login->setLabel('Имя пользователя:');
- $this->add($login);
- // Пароль
- $password = new Password('password', array(
- 'placeholder' => 'Введите ваш пароль',
- 'autocomplete' => 'off'
- ));
- $password->setLabel('Ваш пароль:');
- $this->add($password);
- // Кнопка войти
- $submit = new Submit('button', array(
- 'value' => 'Войти'
- ));
- $this->add($submit);
- // Запомнить меня
- $remember = new Check('remember', array(
- 'value' => 1,
- 'checked'=> true
- ));
- $remember->setLabel('Запомнить меня');
- $this->add($remember);
- // Csrf token
- $csrf = new Hidden('csrf_token', array(
- 'value' => $this->getCsrf()
- ));
- $csrf->addValidator(
- new Identical(array(
- 'value' => $this->getCsrf(),
- 'message' => 'Произошла ошибка "csrf-token" не корректный, обновите окно браузера'
- ))
- );
- $this->add($csrf);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement