Beispiel #1
0
 /**
  *  Creates and HTML select tag
  *  @uses $form->select('project_id', collect(function($project){return array($project->id, $project->title);}, Project::find_all()));
  *  @see function collect
  *  @param string $name of element
  *  @param array $collection array of array's ex. array(array(0,'Bob'), array(1, 'Joe'))
  *  @param array $options key => value pairs for tag attributes
  */
 public function select($name, $collection, $options = array())
 {
     $options = $this->has_errors($name, $options);
     $value = $this->fetch_value($name);
     $option_a = array();
     if (empty($value)) {
         array_push($option_a, FormTagHelper::option('-- Select One --', ''));
     }
     foreach ($collection as $option) {
         if ($value == $option[0]) {
             array_push($option_a, FormTagHelper::option($option[1], $option[0], array('selected' => 'SELECTED')));
         } else {
             array_push($option_a, FormTagHelper::option($option[1], $option[0]));
         }
     }
     $content = join("\n", $option_a);
     return FormTagHelper::select($this->get_id($name), $this->get_name($name), $content, $options);
 }