저자: Nick Sagona, III (nick@popphp.org)
상속: extends Pop\Dom\Dom
예제 #1
0
 /**
  * Update group
  *
  * @param \Pop\Form\Form $form
  * @return void
  */
 public function update(\Pop\Form\Form $form)
 {
     $fields = $form->getFields();
     $group = Table\FieldGroups::findById($fields['id']);
     $group->name = $fields['name'];
     $group->order = (int) $fields['order'];
     $group->dynamic = (int) $fields['dynamic'];
     $group->update();
     $this->data['id'] = $group->id;
 }
예제 #2
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Unsubscribe
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->email) {
         $member = Table\Users::findBy(['email' => $this->email]);
         if (!isset($member->id)) {
             $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email does not exist.'));
         } else {
             if (null !== $member->role_id) {
                 $sess = \Pop\Web\Session::getInstance();
                 $requireLogin = true;
                 $role = Table\Roles::findById($member->role_id);
                 if (isset($role->id) && null !== $role->permissions) {
                     $permissions = unserialize($role->permissions);
                     if (isset($permissions['deny'])) {
                         foreach ($permissions['deny'] as $deny) {
                             if ($deny['resource'] == 'member-login') {
                                 $requireLogin = false;
                             }
                         }
                     }
                 }
                 if ($requireLogin) {
                     if (!isset($sess->member) || isset($sess->member) && $sess->member->id != $member->id) {
                         $memberAdmin = new \Phire\Members\Model\MembersAdmin();
                         $memberAdmin->getByRoleId($member->role_id);
                         $memberUri = isset($memberAdmin->uri) ? $memberAdmin->uri : APP_URI;
                         $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'You must <a href="' . BASE_PATH . $memberUri . '/login">log in</a> to unsubscribe.'));
                     }
                 }
             }
         }
     }
     return $this;
 }
예제 #3
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return UserEmail
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->email) {
         // Check for dupe email
         $user = null;
         $email = null;
         if (null !== $this->email) {
             $user = Table\Users::findBy(['username' => $this->email]);
             if (isset($user->id) && $this->id != $user->id) {
                 $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email already exists.'));
             } else {
                 $email = Table\Users::findBy(['email' => $this->email]);
                 if (isset($email->id) && $this->id != $email->id) {
                     $this->getElement('email')->addValidator(new Validator\NotEqual($this->email1, 'That email already exists.'));
                 }
             }
         }
         // If existing user
         if ((int) $_POST['id'] > 0) {
             if (!empty($this->password1)) {
                 $this->getElement('password2')->setRequired(true)->addValidator(new Validator\Equal($this->password1, 'The passwords do not match.'));
             }
             // Else, if new user, check email and password matches
         } else {
             $this->getElement('password2')->setRequired(true)->addValidator(new Validator\Equal($this->password1, 'The passwords do not match.'));
         }
     }
     return $this;
 }
예제 #4
0
파일: Login.php 프로젝트: phirecms/phirecms
 /**
  * Set the field values
  *
  * @param  array  $values
  * @param  Auth   $auth
  * @return Login
  */
 public function setFieldValues(array $values = null, Auth $auth = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username && null !== $this->password && null !== $auth) {
         $auth->authenticate(html_entity_decode($this->username, ENT_QUOTES, 'UTF-8'), html_entity_decode($this->password, ENT_QUOTES, 'UTF-8'));
         if (!$auth->isValid()) {
             $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'The login was not correct.'));
         } else {
             if (!$auth->adapter()->getUser()->verified) {
                 $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not verified.'));
             } else {
                 if (!$auth->adapter()->getUser()->active) {
                     $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is blocked.'));
                 } else {
                     $role = Table\Roles::findById($auth->adapter()->getUser()->role_id);
                     if (isset($role->id) && null !== $role->permissions) {
                         $permissions = unserialize($role->permissions);
                         if (isset($permissions['deny'])) {
                             foreach ($permissions['deny'] as $deny) {
                                 if ($deny['resource'] == 'login') {
                                     $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not allowed to login.'));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
예제 #5
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @param  array $filters
  * @return \Pop\Form\Form
  */
 public function setFieldValues(array $values = null, $filters = null)
 {
     parent::setFieldValues($values, $filters);
     if ($_POST) {
         // Check the content directory
         if (!file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . $this->content_path)) {
             $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, $this->i18n->__('The content directory does not exist.')));
         } else {
             $checkDirs = \Phire\Project::checkDirs($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . $this->content_path, true);
             if (count($checkDirs) > 0) {
                 $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, $this->i18n->__('The content directory (or subdirectories) are not writable.')));
             }
         }
         // If not SQLite, check the DB parameters
         if (strpos($this->db_adapter, 'Sqlite') === false) {
             $this->getElement('db_name')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database name is required.')));
             $this->getElement('db_username')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database username is required.')));
             $this->getElement('db_password')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database password is required.')));
             $this->getElement('db_host')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database host is required.')));
         }
         // Check the database credentials
         if ($this->isValid()) {
             $oldError = ini_get('error_reporting');
             error_reporting(E_ERROR);
             $dbCheck = Dbs::check(array('database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => str_replace('\\', '_', $this->db_adapter)));
             // If there is a DB error
             if (null != $dbCheck) {
                 $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($dbCheck, 50, '<br />')));
             } else {
                 // Check the database version
                 if (strpos($this->db_adapter, 'Sqlite') === false) {
                     $adapter = stripos($this->db_adapter, 'Pdo\\') !== false ? str_replace('Pdo\\', '', $this->db_adapter) : $this->db_adapter;
                     $db = Db::factory($adapter, array('database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => strtolower(str_replace('Pdo\\', '', $this->db_adapter))));
                     $version = $db->adapter()->version();
                     $version = substr($version, strrpos($version, ' ') + 1);
                     if (strpos($version, '-') !== false) {
                         $version = substr($version, 0, strpos($version, '-'));
                     }
                     if (stripos($this->db_adapter, 'Mysql') !== false) {
                         $dbVerKey = 'Mysql';
                     } else {
                         if (stripos($this->db_adapter, 'Pgsql') !== false) {
                             $dbVerKey = 'Pgsql';
                         } else {
                             $dbVerKey = null;
                         }
                     }
                     if (null !== $dbVerKey && version_compare($version, self::$dbVersions[$dbVerKey]) < 0) {
                         $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($this->i18n->__('The %1 database version must be %2 or greater. (%3 detected.)', array($dbVerKey, self::$dbVersions[$dbVerKey], $version)), 45, '<br />')));
                     }
                 }
             }
             error_reporting($oldError);
         }
     }
     return $this;
 }
예제 #6
0
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username && null !== $this->password) {
         if (sha1($this->username) != $this->usernameHash || sha1($this->password) != $this->passwordHash) {
             $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'The login was not correct.'));
         }
     }
 }
예제 #7
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return InstallConfig
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && !empty($this->config)) {
         if (DB_INTERFACE == '' || DB_NAME == '') {
             $this->getElement('config')->addValidator(new Validator\NotEqual($this->config, 'The configuration file has not been written yet.'));
         }
     }
     return $this;
 }
예제 #8
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return User
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name) {
         $role = Table\Roles::findBy(['name' => $this->name]);
         if (isset($role->id) && $this->id != $role->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That role already exists.'));
         }
     }
     return $this;
 }
예제 #9
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Forgot
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->email) {
         $user = Table\Users::findBy(['email' => $this->email]);
         if (!isset($user->id)) {
             $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email does not exist.'));
         }
     }
     return $this;
 }
예제 #10
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @param  array $settings
  * @return Media
  */
 public function setFieldValues(array $values = null, array $settings = [])
 {
     parent::setFieldValues($values);
     if ($_POST && $_FILES && count($settings) == 4) {
         $upload = new Upload($settings['folder'], $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
         if (!$upload->test($_FILES['file'])) {
             $this->getElement('file')->addValidator(new Validator\NotEqual($this->file, $upload->getErrorMessage()));
         }
     }
     return $this;
 }
예제 #11
0
파일: Tag.php 프로젝트: phirecms/phire-tags
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Category
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->title) {
         // Check for dupe name
         $tag = Table\Tags::findBy(['title' => $this->title]);
         if (isset($tag->id) && $this->id != $tag->id) {
             $this->getElement('title')->addValidator(new Validator\NotEqual($this->title, 'That tag already exists.'));
         }
     }
     return $this;
 }
예제 #12
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Category
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->uri) {
         // Check for dupe name
         $content = Table\Categories::findBy(['uri' => $this->uri]);
         if (isset($content->id) && $this->id != $content->id) {
             $this->getElement('uri')->addValidator(new Validator\NotEqual($this->uri, 'That URI already exists.'));
         }
     }
     return $this;
 }
예제 #13
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return View
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name) {
         // Check for dupe name
         $view = Table\Views::findBy(['name' => $this->name]);
         if (isset($view->id) && $this->id != $view->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That view name already exists.'));
         }
     }
     return $this;
 }
예제 #14
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Install
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && !empty($this->db_adapter)) {
         // If not SQLite, check the DB parameters
         if (stripos($this->db_adapter, 'sqlite') === false) {
             $this->getElement('db_name')->addValidator(new Validator\NotEmpty(null, 'The database name is required.'));
             $this->getElement('db_username')->addValidator(new Validator\NotEmpty(null, 'The database username is required.'));
             $this->getElement('db_password')->addValidator(new Validator\NotEmpty(null, 'The database password is required.'));
             $this->getElement('db_host')->addValidator(new Validator\NotEmpty(null, 'The database host is required.'));
         }
         // Check the content path
         if (!$this->checkContentPath()) {
             $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, wordwrap('The content directory (or subdirectories) either do not exist or are not writable.', 50, '<br />')));
         }
         // Check the database credentials
         if ($this->isValid() && stripos($this->db_adapter, 'sqlite') === false) {
             if (stripos($this->db_adapter, 'pdo_') !== false) {
                 $adapter = 'Pdo';
                 $type = str_replace('pdo_', '', strtolower($this->db_adapter));
             } else {
                 $adapter = ucfirst(strtolower($this->db_adapter));
                 $type = null;
             }
             $oldError = ini_get('error_reporting');
             error_reporting(E_ERROR);
             $creds = ['database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => $type];
             $dbCheck = Db::check($creds, $adapter);
             // If there is a DB error
             if (null != $dbCheck) {
                 $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($dbCheck, 50, '<br />')));
             } else {
                 $db = Db::connect($adapter, $creds);
                 $version = $db->version();
                 $version = substr($version, strrpos($version, ' ') + 1);
                 if (strpos($version, '-') !== false) {
                     $version = substr($version, 0, strpos($version, '-'));
                 }
                 if (stripos($this->db_adapter, 'mysql') !== false && version_compare($version, '5.0') < 0) {
                     $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, 'The MySQL version must be 5.0 or greater.'));
                 } else {
                     if (stripos($this->db_adapter, 'pgsql') !== false && version_compare($version, '9.0') < 0) {
                         $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, 'The PostgreSQL version must be 9.0 or greater.'));
                     }
                 }
             }
             error_reporting($oldError);
         }
     }
     return $this;
 }
예제 #15
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @param  array $settings
  * @return Media
  */
 public function setFieldValues(array $values = null, array $settings = [])
 {
     parent::setFieldValues($values);
     if ($_POST && $_FILES && count($settings) == 4) {
         $upload = new Upload($settings['folder'], $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
         foreach ($_FILES as $file) {
             if (!empty($file['name'])) {
                 if (!$upload->test($file)) {
                     $this->getElement('error')->addValidator(new Validator\NotEqual('1', $upload->getErrorMessage() . ' (' . $file['name'] . ')'));
                 }
             }
         }
     }
     return $this;
 }
예제 #16
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Template
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name) {
         // Check for dupe device
         if ($this->template_parent_id != '----' && $this->device != '----') {
             $parent = Table\Templates::findBy(['id' => (int) $this->template_parent_id, 'device' => $this->device]);
             $children = Table\Templates::findBy(['parent_id' => (int) $this->template_parent_id, 'device' => $this->device, 'id !=' => $this->id]);
             if ($parent->hasRows() || $children->hasRows()) {
                 $this->getElement('device')->addValidator(new Validator\NotEqual($this->device, 'That device has already been added for this template set.'));
             }
         }
     }
     return $this;
 }
예제 #17
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Update
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->resource) {
         $curl = new Curl('http://updates.phirecms.org/test');
         $curl->setFields($this->getFields());
         $curl->setPost(true);
         $curl->send();
         if ($curl->getCode() == 401) {
             $json = json_decode($curl->getBody(), true);
             $this->getElement('ftp_address')->addValidator(new Validator\NotEqual($this->ftp_address, $json['error']));
         }
     }
     return $this;
 }
예제 #18
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Forgot
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->email) {
         $user = Table\Users::findBy(['email' => $this->email]);
         if (!isset($user->id)) {
             $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email does not exist.'));
         } else {
             $role = new Model\Role();
             if (!$role->canSendReminder($user->role_id)) {
                 $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That request cannot be processed.'));
             }
         }
     }
     return $this;
 }
예제 #19
0
 /**
  * Constructor
  *
  * Instantiate the form object
  *
  * @param  int    $id
  * @param  array  $fields
  * @param  string $action
  * @param  string $method
  * @return SessionConfig
  */
 public function __construct($id = null, array $fields, $action = null, $method = 'post')
 {
     $configs = \Phire\Sessions\Table\UserSessionConfig::findAll();
     $configsAry = [];
     foreach ($configs->rows() as $config) {
         $configsAry[] = $config->role_id;
     }
     $roles = Table\Roles::findAll();
     $roleValues = ['----' => '----'];
     foreach ($roles->rows() as $role) {
         if (!in_array($role->id, $configsAry) || $id == $role->id) {
             $roleValues[$role->id] = $role->name;
         }
     }
     $fields[0]['role_id']['value'] = $roleValues;
     parent::__construct($fields, $action, $method);
     $this->setAttribute('id', 'session-form');
     $this->setIndent('    ');
 }
예제 #20
0
 /**
  * Set the field values
  *
  * @param  array  $values
  * @param  Auth   $auth
  * @return Login
  */
 public function setFieldValues(array $values = null, Auth $auth = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username && null !== $this->password && null !== $auth) {
         $auth->authenticate(html_entity_decode($this->username, ENT_QUOTES, 'UTF-8'), html_entity_decode($this->password, ENT_QUOTES, 'UTF-8'));
         if (!$auth->isValid()) {
             $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'The login was not correct.'));
         } else {
             if (!$auth->adapter()->getUser()->verified) {
                 $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not verified.'));
             } else {
                 if (!$auth->adapter()->getUser()->active) {
                     $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is blocked.'));
                 }
             }
         }
     }
     return $this;
 }
예제 #21
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return MediaLibrary
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name && null !== $this->folder) {
         // Check for dupe name
         $library = Table\MediaLibraries::findBy(['name' => $this->name]);
         if (isset($library->id) && $this->id != $library->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That name already exists.'));
         }
         // Check for dupe name
         $library = Table\MediaLibraries::findBy(['folder' => $this->folder]);
         if (isset($library->id) && $this->id != $library->id) {
             $this->getElement('folder')->addValidator(new Validator\NotEqual($this->folder, 'That folder already exists.'));
             if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $this->folder)) {
                 $this->getElement('folder')->addValidator(new Validator\NotEqual($this->folder, 'That folder already exists on disk.'));
             }
         }
     }
     return $this;
 }
예제 #22
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return RegisterEmail
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->email) {
         // Check for dupe email
         if (null !== $this->email) {
             $user = Table\Users::findBy(['username' => $this->email]);
             if (isset($user->id)) {
                 $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That username is not allowed.'));
             } else {
                 $email = Table\Users::findBy(['email' => $this->email]);
                 if (isset($email->id)) {
                     $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email is not allowed.'));
                 }
             }
         }
         // Check password matches
         $this->getElement('password2')->addValidator(new Validator\Equal($this->password1, 'The passwords do not match.'));
     }
     return $this;
 }
예제 #23
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Profile
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username) {
         // Check for dupe username
         $user = null;
         if (null !== $this->username) {
             $user = Table\Users::findBy(['username' => $this->username]);
             if (isset($user->id) && $this->id != $user->id) {
                 $this->getElement('username')->addValidator(new Validator\NotEqual($this->username, 'That username is not allowed.'));
             }
         }
         // Check for dupe email
         $email = Table\Users::findBy(['email' => $this->email]);
         if (isset($email->id) && $this->id != $email->id) {
             $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email is not allowed.'));
         }
         // Check password matches
         if (!empty($this->password1)) {
             $this->getElement('password2')->setRequired(true)->addValidator(new Validator\Equal($this->password1, 'The passwords do not match.'));
         }
     }
     return $this;
 }
예제 #24
0
파일: form5.php 프로젝트: nicksagona/PopPHP
<?php

require_once '../../bootstrap.php';
use Pop\Form\Form;
use Pop\Validator;
try {
    $fields = array('username' => array('type' => 'text', 'value' => 'Username here...', 'label' => 'Username:'******'required' => true, 'attributes' => array('size' => 40), 'validators' => array(new Validator\AlphaNumeric(), new Validator\LengthLt(6))), 'email' => array('type' => 'text', 'label' => 'Email:', 'required' => true, 'attributes' => array('size' => 40), 'validators' => new Validator\Email()), 'password' => array('type' => 'password', 'label' => 'Password:'******'required' => true, 'attributes' => array('size' => 40), 'validators' => new Validator\LengthGt(6)), 'checkbox_colors' => array('type' => 'checkbox', 'label' => 'Colors:', 'required' => true, 'value' => array('Red' => 'Red', 'Green' => 'Green', 'Blue' => 'Blue'), 'validators' => new Validator\Included(array('Red', 'Green'))), 'radio_colors' => array('type' => 'radio', 'label' => 'Colors:', 'required' => true, 'value' => array('Red' => 'Red', 'Green' => 'Green', 'Blue' => 'Blue')), 'select_colors' => array('type' => 'select', 'label' => 'Colors:', 'value' => array('--' => '--', 'Red' => 'Red', 'Green' => 'Green', 'Other Colors' => array('Purple' => 'Purple', 'Gold' => 'Gold', 'Mauve' => 'Mauve'), 'Blue' => 'Blue', 'No Colors' => array('Black' => 'Black', 'White' => 'White')), 'attributes' => array('multiple' => 'multiple'), 'marked' => array('Black', 'Gold', 'Blue')), 'submit' => array('type' => 'submit', 'value' => 'SUBMIT', 'attributes' => array('style' => 'padding: 5px; border: solid 2px #000; background-color: #00f; color: #fff; font-weight: bold;')));
    $form = new Form($_SERVER['PHP_SELF'], 'post', $fields, '    ');
    $form->setTemplate('form.phtml');
    if ($_POST) {
        $form->setFieldValues($_POST, array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')));
        if (!$form->isValid()) {
            $form->render();
        } else {
            echo 'Form is valid.<br />' . PHP_EOL;
            $form->filter(array('html_entity_decode' => array(ENT_QUOTES, 'UTF-8')));
            print_r($form->getFields());
        }
    } else {
        $form->render();
    }
    echo PHP_EOL . PHP_EOL;
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
예제 #25
0
 /**
  * Constructor
  *
  * Instantiate the form object
  *
  * @param  array  $fields
  * @param  string $action
  * @param  string $method
  * @return MapLocation
  */
 public function __construct(array $fields = null, $action = null, $method = 'post')
 {
     parent::__construct($fields, $action, $method);
     $this->setAttribute('id', 'map-form');
     $this->setIndent('    ');
 }
예제 #26
0
파일: form4.php 프로젝트: nicksagona/PopPHP
<?php

require_once '../../bootstrap.php';
use Pop\Form\Form;
use Pop\Validator;
try {
    $fields = array('username' => array('type' => 'text', 'label' => 'Username:'******'required' => true, 'attributes' => array('size' => 40), 'validators' => new Validator\AlphaNumeric()), 'password' => array('type' => 'password', 'label' => 'Password:'******'required' => true, 'attributes' => array('size' => 40)), 'my_captcha' => array('type' => 'captcha', 'label' => 'Please Solve: ', 'attributes' => array('size' => 10), 'expire' => 120), 'submit' => array('type' => 'submit', 'value' => 'SUBMIT'));
    $form = new Form($_SERVER['PHP_SELF'], 'post', $fields, '    ');
    if ($_POST) {
        $form->setFieldValues($_POST, array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')));
        if (!$form->isValid()) {
            $form->render();
        } else {
            // Option to clear out and reset security token
            $form->clear();
            echo 'Form is valid.<br />' . PHP_EOL;
            print_r($form->getFields());
        }
    } else {
        $form->render();
    }
    echo PHP_EOL . PHP_EOL;
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
예제 #27
0
 public function testRenderException()
 {
     $this->setExpectedException('Pop\\Form\\Exception');
     $f = new Form('/submit', 'post');
     $f->render();
 }
예제 #28
0
 /**
  * Update user
  *
  * @param  \Pop\Form\Form $form
  * @param  \Pop\Config    $config
  * @return void
  */
 public function update(\Pop\Form\Form $form, $config)
 {
     $encOptions = $config->encryptionOptions->asArray();
     $fields = $form->getFields();
     $type = Table\UserTypes::findById($fields['type_id']);
     $user = Table\Users::findById($fields['id']);
     if (isset($user->id)) {
         // If there's a new password, set according to the user type
         if ($fields['password1'] != '' && $fields['password2'] != '') {
             $user->password = self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions);
         }
         // Set role
         if (isset($fields['role_id'])) {
             $roleId = $fields['role_id'] == 0 ? null : $fields['role_id'];
         } else {
             $roleId = $user->role_id;
         }
         // Set verified and attempts
         $verified = isset($fields['verified']) ? $fields['verified'] : $user->verified;
         $failedAttempts = isset($fields['failed_attempts']) ? $fields['failed_attempts'] : $user->failed_attempts;
         $first = null === $user->role_id && null === $user->logins && $type->login;
         if (isset($fields['profile']) && $fields['profile']) {
             $siteIds = $user->site_ids;
         } else {
             $siteIds = isset($fields['site_ids']) ? serialize($fields['site_ids']) : serialize(array());
         }
         // Save the user's updated data
         $user->role_id = $roleId;
         $user->username = isset($fields['username']) ? $fields['username'] : $fields['email1'];
         $user->email = $fields['email1'];
         $user->verified = $verified;
         $user->failed_attempts = $failedAttempts;
         $user->site_ids = $siteIds;
         $user->updated = date('Y-m-d H:i:s');
         $sess = Session::getInstance();
         if (isset($fields['reset_pwd']) && $fields['reset_pwd']) {
             $user->updated_pwd = date('Y-m-d H:i:s');
             unset($sess->reset_pwd);
         }
         $sess->last_user_id = $user->id;
         if ($sess->user->id == $user->id) {
             $sess->user->username = $user->username;
             $sess->user->site_ids = unserialize($siteIds);
         }
         $user->update();
         $this->data['id'] = $user->id;
         FieldValue::update($fields, $user->id);
         // Send verification if needed
         if ($first) {
             $this->sendApproval($user, $type);
         }
     }
 }
예제 #29
0
 public function __construct(array $fields = null, $action = null, $method = 'post')
 {
     $fields = ['name' => ['type' => 'text', 'label' => 'Name (Optional)', 'attributes' => ['size' => 60]], 'comment' => ['type' => 'textarea', 'label' => 'Comment (Required)', 'required' => true, 'attributes' => ['rows' => 5, 'cols' => 65], 'validators' => new LengthLte(160, 'The comment must be 160 characters or less.')], 'submit' => ['type' => 'submit', 'value' => 'Submit']];
     parent::__construct($fields, $action, $method);
 }
예제 #30
0
 public function __construct(array $fields = null, $action = null, $method = 'post')
 {
     $fields = ['name' => ['type' => 'text', 'label' => 'Name (Optional)', 'attributes' => ['size' => 60]], 'comment' => ['type' => 'textarea', 'label' => 'Comment (Required)', 'required' => true, 'attributes' => ['rows' => 5, 'cols' => 65]], 'submit' => ['type' => 'submit', 'value' => 'Submit']];
     parent::__construct($fields, $action, $method);
 }