[eluser]helmutbjorg[/eluser]
To do the mod above all it took were 4 new lines...
I copied the form_dropdown() function from system/helpers/form_helper.php
Code:
/**
* Drop-down Menu
*
* @access public
* @param string
* @param array
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_dropdown'))
{
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
{
if ( ! is_array($selected))
{
$selected = array($selected);
}
// If no selected state was submitted we will attempt to set it automatically
if (count($selected) === 0)
{
// If the form name appears in the $_POST array we have a winner!
if (isset($_POST[$name]))
{
$selected = array($_POST[$name]);
}
}
if ($extra != '') $extra = ' '.$extra;
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
$form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
foreach ($options as $key => $val)
{
$key = (string) $key;
$val = (string) $val;
$sel = (in_array($key, $selected))?' selected="selected"':'';
$form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
}
$form .= '</select>';
return $form;
}
}
And copied it to system/application/helpers/MY_form_helper.php
Code:
/**
* Drop-down Menu
*
* @access public
* @param string
* @param array
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_dropdown'))
{
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
{
if ( ! is_array($selected))
{
$selected = array($selected);
}
// If no selected state was submitted we will attempt to set it automatically
if (count($selected) === 0)
{
// If the form name appears in the $_POST array we have a winner!
if (isset($_POST[$name]))
{
$selected = array($_POST[$name]);
}
}
if ($extra != '') $extra = ' '.$extra;
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
$form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
foreach ($options as $key => $val)
{
/* START CUSTOM CODE */
if(is_array($val)) {
if(isset($val['key'])) $key = $val['key'];
if(isset($val['value'])) $val = $val['value'];
}
/* END CUSTOM CODE */
$key = (string) $key;
$val = (string) $val;
$sel = (in_array($key, $selected))?' selected="selected"':'';
$form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
}
$form .= '</select>';
return $form;
}
}
I think this is a fairly un-obtrusive way of fixing the problem.