コード例 #1
0
 public function __construct($type, array $attributes = array(), $containerTag = 'div')
 {
     isset($attributes['id']) or $attributes['id'] = null;
     if (isset($attributes['label'])) {
         $this->label = $this->tag('label', array('name' => $attributes['label'], 'for' => $attributes['id']));
         unset($attributes['label']);
     }
     $type = strtolower($type);
     $this->input = $this->tag($type);
     if (in_array($type, array('select', 'radio')) && isset($attributes['options'])) {
         if ($type == 'radio') {
             $this->input = $this->tag('div', array('data-fieldset' => 'radio-group'));
             $this->input->setOriginalName($type);
         }
         $copy = $attributes;
         unset($copy['options']);
         foreach ($attributes['options'] as $k => $v) {
             if ($type == 'select') {
                 $this->input->addTag($this->tag('option', array('value' => $k, 'name' => $v)));
             } else {
                 $copy = array('value' => $k, 'id' => $attributes['name'] . '-' . $k) + $copy;
                 $this->input->addTag($this->tag('radio', $copy));
                 $this->input->addTag($this->tag('label', $v)->setAttribute('for', $copy['id']));
                 unset($attributes['type']);
             }
         }
         unset($attributes['options']);
     }
     $this->input->setAttributes($attributes);
     parent::__construct($containerTag);
 }
コード例 #2
0
ファイル: Fieldset.php プロジェクト: joegreen0991/fieldset
 public function __construct(array $attributes = array())
 {
     parent::__construct('fieldset');
     $this->setAttributes($attributes);
 }