Пример #1
0
 /**
  * Helper function for generating simple select HTML fragments
  *
  * @param Zend_Form_Element_Select $element
  * @param string $cssEtc optional attribute string for <select> tag
  * @param string $wrapOptionHtml optional HTML that wraps each <option>, split by an asterisk
  *
  * @return string
  */
 public function simpleSelect($element, $cssEtc = '', $wrapOptionHtml = '')
 {
     $wrapOptionHtmlStart = $wrapOptionHtmlEnd = '';
     if (strpos($wrapOptionHtml, '*') !== false) {
         list($wrapOptionHtmlStart, $wrapOptionHtmlEnd) = explode('*', $wrapOptionHtml);
     }
     $output = sprintf("<select name=\"%s\" id=\"%s\"%s>\n", $element->getName(), $element->getId(), $cssEtc != '' ? " {$cssEtc}" : '');
     $options = $element->getMultiOptions();
     foreach ($options as $key => $val) {
         $output .= sprintf("  %s<option value=\"%s\"%s>%s</option>%s\n", $wrapOptionHtmlStart, $key, (string) $key == (string) $element->getValue() && $key !== '' ? ' selected="selected"' : '', $val, $wrapOptionHtmlEnd);
     }
     $output .= "</select>\n";
     return $output;
 }