/** * * @throws EE_Error * @return string of html to display the field */ function display() { if (!$this->_input instanceof EE_Form_Input_With_Options_Base) { throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); } EE_Registry::instance()->load_helper('Array'); $html = EEH_HTML::nl(0, 'select'); $html .= '<select'; $html .= ' id="' . $this->_input->html_id() . '"'; $html .= ' name="' . $this->_input->html_name() . '"'; $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); $html .= ' class="' . $class . '"'; // add html5 required $html .= $this->_input->required() ? ' required' : ''; $html .= ' style="' . $this->_input->html_style() . '"'; $html .= '>'; // EEH_HTML::indent( 1, 'select' ); if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { EEH_HTML::indent(1, 'optgroup'); foreach ($this->_input->options() as $opt_group_label => $opt_group) { $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; EEH_HTML::indent(1, 'option'); $html .= $this->_display_options($opt_group); $html .= EEH_HTML::indent(-1, 'option'); $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; } EEH_HTML::indent(-1, 'optgroup'); } else { $html .= $this->_display_options($this->_input->options()); } $html .= EEH_HTML::nl(0, 'select') . '</select>'; // $html.= EEH_HTML::nl( -1, 'select' ) . '</select>'; return $html; }
/** * * @throws EE_Error * @return string of html to display the field */ public function display() { if (!$this->_input instanceof EE_Form_Input_With_Options_Base) { throw new EE_Error(sprintf(__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso"))); } $html = EEH_HTML::nl(0, 'select'); $html .= '<select multiple'; $html .= ' id="' . $this->_input->html_id() . '"'; $html .= ' name="' . $this->_input->html_name() . '[]"'; $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); $html .= ' class="' . $class . '"'; // add html5 required $html .= $this->_input->required() ? ' required' : ''; $html .= ' style="' . $this->_input->html_style() . '"'; $html .= '>'; EE_Registry::instance()->load_helper('Array'); EEH_HTML::indent(1, 'select'); if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { throw new EE_Error(sprintf(__("Select multiple display strategy does not allow for nested arrays of options.", "event_espresso"))); } else { $html .= $this->_display_options($this->_input->options()); } $html .= EEH_HTML::nl(-1, 'select') . "</select>"; return $html; }
/** * Makes sure $arr is a flat array, not a multidimensional one * @param array $arr * @return array */ protected function _flatten_select_options($arr) { $flat_array = array(); EE_Registry::instance()->load_helper('Array'); if (EEH_Array::is_multi_dimensional_array($arr)) { foreach ($arr as $sub_array) { foreach ($sub_array as $key => $value) { $flat_array[$key] = $value; $this->_set_label_size($value); } } } else { foreach ($arr as $key => $value) { $flat_array[$key] = $value; $this->_set_label_size($value); } } return $flat_array; }