Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

render_select_option()

Description

Renders a select element.

Takes an array of options (as returned from sql_query and returns a valid
select element. The query must have a column aliased as value and label.
Option groups can be created as well with the optional $groupby parameter.
This function retrieves a language field in the form of
$lang['cfg-<fieldname>'] to use for the element label.

<code>
$options = sql_select("SELECT name AS label, ref AS value FROM resource_type");

render_select_option('myfield', $options, 18);
</code>

Parameters

ColumnTypeDefaultDescription
$fieldname string Name to use for the field.
$opt_array array Array of options to fill the select with
$selected mixed If matches value the option is marked as selected
$groupby string '' Column to group by

Return

string HTML output.

Location

include/config_functions.php lines 27 to 55

Definition

 
function render_select_option($fieldname$opt_array$selected$groupby '')
{
    global 
$errorfields$lang;

    
$output '';
    
$output .= "<tr><th><label for=\"$fieldname\">" $lang['cfg-' $fieldname] . "</label></th>";
    
$output .= "<td><select name=\"$fieldname\">";

    if (
$groupby != '') {
        
$cur_group $opt_array[0][$groupby];
        
$output .= "<optgroup label=\"$cur_group\">";
    }

    foreach (
$opt_array as $option) {
        if (
$groupby != '' && $cur_group != $option[$groupby]) {
            
$cur_group $option[$groupby];
            
$output .= "</optgroup><optgroup label=\"$cur_group\">";
        }
        
$output .= "<option ";
        
$output .= $option['value'] == $selected 'selected="selected" ' '';
        
$output .= "value=\"{$option['value']}\">{$option['label']}</option>";
    }

    
$output .= '</optgroup>';
    
$output .= isset($errorfields[$fieldname]) ? '<span class="error">* ' $errorfields[$fieldname] . '</span>' '';
    
$output .= '</td></tr>';

    return 
$output;
}

This article was last updated 30th April 2025 21:35 Europe/London time based on the source file dated 25th April 2025 15:15 Europe/London time.