Ejemplo n.º 1
0
function getSelectHtml($name, $currentValue, $options, $attributes = array())
{
    $defaultAttributes = array('size' => 1, 'id' => $name, 'name' => $name);
    $finalAttributes = array_merge($defaultAttributes, $attributes);
    $content = "";
    foreach ($options as $optionKey => $optionValue) {
        $optionAttributes = array();
        if ($currentValue === $optionKey) {
            $optionAttributes['selected'] = 'selected';
        }
        $content .= getOptionHtml($optionKey, $optionValue, $optionAttributes);
    }
    return getElementHtml('select', $finalAttributes, $content);
}
Ejemplo n.º 2
0
function getOptionGroup($options, $currentValue)
{
    $content = '';
    foreach ($options as $optionKey => $optionValue) {
        if (is_array($optionValue)) {
            $content .= '<optgroup label="' . $optionKey . '">' . getOptionGroup($optionValue, $currentValue) . '</optgroup>';
        } else {
            $optionAttributes = array();
            if ($currentValue == $optionKey) {
                $optionAttributes['selected'] = 'selected';
            }
            $content .= getOptionHtml($optionKey, $optionValue, $optionAttributes);
        }
    }
    return $content;
}