저자: Nick Sagona, III (dev@nolainteractive.com)
상속: implements ArrayAccess
예제 #1
0
 public function testAddFieldsFromTableException()
 {
     $this->setExpectedException('Pop\\Form\\Exception');
     Users::setDb(Db::factory('Sqlite', array('database' => __DIR__ . '/../tmp/test.sqlite')));
     $f = Fields::factory(array());
     $f->addFieldsFromTable(array());
 }
예제 #2
0
use Pop\Form\Fields;
use Pop\Form\Element;
use Pop\Db\Record;
class Users extends Record
{
}
class User extends Form
{
}
try {
    // Define DB credentials
    $db = Db::factory('Mysqli', array('database' => 'helloworld', 'host' => 'localhost', 'username' => 'hello', 'password' => '12world34'));
    Users::setDb($db);
    $attribs = array('text' => array('size' => 40), 'textarea' => array('rows' => 5, 'cols' => 40));
    $values = array('id' => array('type' => 'hidden'));
    $fields = Fields::factory(Users::getTableInfo(), $attribs, $values, 'access');
    $fields->addFields(array('submit' => array('type' => 'submit', 'label' => ' ', 'value' => 'SUBMIT')));
    $form = new User($_SERVER['REQUEST_URI'], 'post', $fields->getFields());
    if ($_POST) {
        $form->setFieldValues($_POST);
        if ($form->isValid()) {
            echo 'Form is valid!';
        } else {
            $form->render();
        }
    } else {
        $form->render();
    }
    echo PHP_EOL . PHP_EOL;
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
예제 #3
0
 /**
  * Method to create the form fields
  *
  * @param  array $values
  * @throws Exception
  * @return void
  */
 protected function createFields(array $values = null)
 {
     // Loop through the field config and build the fields and build the fields
     if (count($this->fieldConfig) > 0) {
         // If the fields are a group of fields
         $keys = array_keys($this->fieldConfig);
         if (is_numeric($keys[0])) {
             $fields = [];
             foreach ($this->fieldConfig as $ary) {
                 $k = array_keys($ary);
                 if (isset($k[0])) {
                     $this->groups[] = $k[0];
                 }
                 $fields = array_merge($fields, $ary);
             }
             $this->fieldConfig = $fields;
         }
         foreach ($this->fieldConfig as $name => $field) {
             if (is_array($field) && isset($field['type'])) {
                 if ($field['type'] == 'file') {
                     $this->hasFile = true;
                 }
                 $this->addElement(Fields::factory($name, $field, $values));
             }
         }
     }
 }