setFieldValues() public method

Set the field values. Optionally, you can apply filters to the passed values via callbacks and their parameters
public setFieldValues ( array $values = null, array $filters = null ) : Form
$values array
$filters array
return Form
示例#1
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;
 }
示例#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
  * @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;
 }
示例#4
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;
 }
示例#5
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.'));
         }
     }
 }
示例#6
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;
 }
示例#7
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;
 }
示例#8
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;
 }
示例#9
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;
 }
示例#10
0
 /**
  * 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;
 }
示例#11
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;
 }
示例#12
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;
 }
示例#13
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;
 }
示例#14
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;
 }
示例#15
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;
 }
示例#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 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;
 }
示例#18
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;
 }
示例#19
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;
 }
示例#20
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;
 }
示例#21
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;
 }
示例#22
0
<?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;
}
示例#23
0
 public function testFilter()
 {
     $fields = array('username' => array('type' => 'text', 'value' => 'Username here...', 'label' => 'Username:'******'required' => true, 'attributes' => array('size' => 40)));
     $f = new Form('/submit', 'post', $fields);
     $f->setFieldValues(array('username' => '<p>te\'st"<script>user</script></p>'), array('strip_tags' => '<p>', 'htmlentities' => array(ENT_QUOTES, 'UTF-8')));
     $this->assertEquals('&lt;p&gt;te&#039;st&quot;user&lt;/p&gt;', $f->username);
     $f->filter(array('html_entity_decode' => array(ENT_QUOTES, 'UTF-8')));
     $this->assertEquals('<p>te\'st"user</p>', $f->username);
 }