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_dropdown_question()

Description

render_dropdown_question - Used to display a question with a dropdown selector

IMPORTANT: careful when having to handle untrusted data! If you have to pass it to elements, make sure they're encoded
accordingly.

div_class?: list<string>,
div_content?: string,
div_extra_attr?: string,
input_class?: string,
onchange?: string,
} $ctx Rendering context. Should be used to inject different elements (e.g set the div class, add onchange for select).

Parameters

ColumnTypeDefaultDescription
$label string Label of question
$inputname string Name of input field
$options array array Array of options (value and text pairs) (eg. array('pixelwidthmin'=>'From','pixelwidthmin'=>'To')
$current string|list "" The current selected value. For a multiple selector, a list of currently selected values.
$extra string "" Extra attributes used on the selector element
$ctx array
* array{ no_div_class_question?: bool,

Location

include/render_functions.php lines 1697 to 1734

Definition

 
function render_dropdown_question($label$inputname$options = array(), string|array $current=""$extra="", array $ctx = array()): void
    
{
    
$input_name_escaped escape($inputname);
    
$div_class = isset($ctx["no_div_class_question"]) ? [] : ["Question"];
    if(isset(
$ctx["div_class"]) && is_array($ctx["div_class"]) && !empty($ctx["div_class"]))
        {
        
$div_class array_merge($div_class$ctx["div_class"]);
        }
    
$div_content $ctx["div_content"] ?? "";
    
$div_extra_attr $ctx["div_extra_attr"] ?? "";
    
$input_class = isset($ctx["input_class"]) ? $ctx["input_class"] : "stdwidth";

    
$onchange = (isset($ctx["onchange"]) && trim($ctx["onchange"]) != "" trim($ctx["onchange"]) : "");
    
$onchange = ($onchange != "" sprintf("onchange=\"%s\""$onchange) : "");

    
$extra .= {$onchange}";

    
$is_option_selected = static fn (string $option): bool => is_array($current)
        ? 
in_array($option$current)
        : 
trim((string) $option) === trim((string) $current);
    
?>
    <div class=" echo escape(implode(" "$div_class)); ?> echo $div_extra_attr?>>
        <label for=" echo $input_name_escaped?>"> echo escape($label); ?></label>
        <select  name=" echo $input_name_escaped?>" class=" echo escape($input_class); ?>" id=" echo $input_name_escaped?> echo $extra?>>
        
        
foreach ($options as $optionvalue=>$optiontext)
            {
            
?>
            <option value=" echo escape(trim((string)$optionvalue))?> if ($is_option_selected($optionvalue)) {?>selected ?>> echo escape(trim((string)$optiontext))?></option>
            
            
}
        
?>
        </select>
         echo $div_content?>
        <div class="clearerleft"></div>
    </div>
    
    
}

This article was last updated 14th June 2026 10:35 Europe/London time based on the source file dated 10th June 2026 16:35 Europe/London time.