예제 #1
0
 /**
  * Render the given field
  *
  * @return string
  */
 protected function render_field()
 {
     $html = "\n";
     if (!$this->attributes) {
         $this->attributes = array();
     }
     // Configure the attributes
     $attributes = $this->attributes;
     // Get the current value
     if ($this->value !== NULL) {
         $value = $this->value;
     } else {
         $value = $this->validation->value($this->field);
     }
     if ($this->label) {
         $html .= '<label for="' . $this->field . '">' . $this->label . "</label>";
     }
     if ($this->type == 'select') {
         $html .= \Core\HTML::select($this->field, $this->options, $value, $attributes);
     } elseif ($this->type == 'textarea') {
         $html .= \Core\HTML::tag('textarea', $value, $attributes);
     } else {
         // Input field
         $attributes = $attributes + array('type' => $this->type, 'value' => $value);
         $html .= \Core\HTML::tag('input', FALSE, $attributes);
     }
     // If there was a validation error
     if ($error = $this->validation->error($this->field)) {
         if (isset($attributes['class'])) {
             $attributes['class'] .= ' error';
         } else {
             $attributes['class'] = $this->field . ' ' . $this->type . ' error';
         }
         $html .= "\n<div class=\"error_message\">{$error}</div>";
     }
     if ($this->tag) {
         $html = \Core\HTML::tag($this->tag, $html . "\n") . "\n";
     }
     return $html;
 }