Exemplo n.º 1
0
 /**
  *  create the form from an array of data
  */
 public static function create_from_data($config, $data)
 {
     $form = new Form($config);
     if (array_key_exists('attributes', $data)) {
         $form->set_attributes($data['attributes']);
     }
     if (array_key_exists('defaults', $data)) {
         $form->set_defaults($data['defaults']);
     }
     foreach ($data['fields'] as $field_src) {
         $field = array_merge(array('options' => array(), 'constraints' => array()), $field_src);
         $form->add_field($field['name'], $field['type'], $field['options'], $field['constraints']);
     }
     return $form;
 }
Exemplo n.º 2
0
 /**
  * @covers Acreage::Form::add_field
  */
 public function test_add_field_adds_correct_type_for_files()
 {
     $mock_config = array('validator' => 'mock.validator');
     $subject = new Form($mock_config);
     $subject->add_field('field', 'file');
     $this->assertInstanceOf('Acreage\\Fields\\File', $subject->fields[0]);
 }