Example #1
0
 /**
  * Renders a select field.
  *
  * @return string (X)HTML.
  */
 protected function renderSelectField()
 {
     $o = '';
     $brackets = $this->field->isMultiSelection() ? '[]' : '';
     if ($this->field->isRealSelect()) {
         $size = $this->field->getSize();
         $size = empty($size) ? '' : ' size="' . $size . '"';
         $multi = $this->field->isMultiSelection() ? ' multiple="multiple"' : '';
         $o .= '<select id="' . $this->id . '" name="' . $this->name . $brackets . '"' . $size . $multi . '>';
     } else {
         $orient = $this->field->isVertical() ? 'vert' : 'horz';
     }
     foreach ($this->field->getOptions() as $opt) {
         $opt = explode("●", $opt);
         if (count($opt) > 1) {
             $f = true;
             $opt = $opt[1];
         } else {
             $f = false;
             $opt = $opt[0];
         }
         if (function_exists('advfrm_custom_field_default')) {
             $cust_f = advfrm_custom_field_default($this->form, $this->field->getName(), $opt, isset($_POST['advfrm']));
         }
         if (isset($cust_f)) {
             $f = $cust_f;
         } else {
             $f = isset($_POST['advfrm']) && isset($_POST[$this->name]) && ($this->field->isMultiSelection() ? in_array($opt, array_map('stsl', $_POST[$this->name])) : stsl($_POST[$this->name]) == $opt) || !isset($_POST['advfrm']) && $f;
         }
         $sel = $f ? $this->field->isRealSelect() ? ' selected="selected"' : ' checked="checked"' : '';
         if ($this->field->isRealSelect()) {
             $o .= '<option' . $sel . '>' . XH_hsc($opt) . '</option>';
         } else {
             $o .= '<div class="' . $orient . '"><label>' . tag('input type="' . $this->field->getType() . '" name="' . $this->name . $brackets . '" value="' . XH_hsc($opt) . '"' . $sel) . '&nbsp;' . XH_hsc($opt) . '</label></div>';
         }
     }
     if ($this->field->isRealSelect()) {
         $o .= '</select>';
     }
     return $o;
 }