/**
  * Renders an opening tab div
  *
  * @param string $title The tab title
  * @param string $id tab id (optional). Generated from $title if empty.
  *
  * @return string
  */
 function renderTabStart($title, $id = '')
 {
     if (empty($id)) {
         $id = 'tab-' . $title;
     }
     $id = FormHelper::cleanHtmlId($id);
     if (isset($this->tabs[$id])) {
         trigger_error('Warning: id "' . $id . '" has already been used as tab identifier.', E_USER_WARNING);
     } else {
         $this->tabs[$id] = $title;
     }
     return '<div id="' . $id . '">';
 }
Exemplo n.º 2
0
 /**
  * Renders a form input field
  *
  * The attributes parameter accepts any html properties plus the following:
  * - "label": set this value to wrap the input field into a label with the given value in front of the input field.
  * - "help": Set to display a (help) text underneith the field.
  *
  * @static
  * @access public
  *
  * @param string $type The type of the input field. (E.g. "text" or "hidden").
  * @param string $name The name of the input field.
  * @param string $value The value of the input field.
  * @param array $attributes Array of (html) attributes.
  *
  * @return string Html rendered form element.
  */
 static function input($type, $name, $value, $attributes = array())
 {
     $valid_types = array('text', 'hidden', 'password', 'submit', 'reset');
     if (!in_array($type, $valid_types)) {
         return '[Only types "' . join('", "', $valid_types) . '" are allowed in FormHelper::input()]';
     }
     if ($type == 'text' && isset($attributes['rows']) && intval($attributes['rows']) > 0) {
         $tag = 'textarea';
         $attributes['rows'] = intval($attributes['rows']);
     } else {
         $tag = 'input';
         $attributes['type'] = $type;
         $attributes['value'] = $value;
     }
     $attributes['id'] = !empty($attributes['id']) ? $attributes['id'] : $name;
     $attributes['id'] = FormHelper::cleanHtmlId($attributes['id']);
     $attributes['name'] = $name;
     $label = '';
     if (isset($attributes['label'])) {
         $label = $attributes['label'] . ' ';
         unset($attributes['label']);
     }
     $help = '';
     if (isset($attributes['help'])) {
         $help = $attributes['help'] . ' ';
         unset($attributes['help']);
     }
     $attr = FormHelper::buildHtmlAttributes($attributes);
     $html = '<' . $tag . $attr;
     if ($tag == 'textarea') {
         $html .= '>';
         $html .= htmlspecialchars($value);
         $html .= '</' . $tag . '>';
     } else {
         $html .= ' />';
     }
     if (!empty($label)) {
         $html = '<label>' . $label . $html . '</label>';
     }
     if (!empty($help)) {
         $html .= $help;
     }
     return $html;
 }