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

config_percent_range()

Description

Generate a percentage range input

Parameters

ColumnTypeDefaultDescription
$name string The name of the configuration variable to be added.
$label string The user text displayed to label the text block. Usually a $lang string.
$current string The current value of the config variable being set.
$width int 420 The width of the input field in pixels. Default: 420.
$title string null The title attribute of the element
$help_link string "" Help link to be displayed alongside the label.

Location

include/config_functions.php lines 2110 to 2161

Definition

 
function config_percent_range($name$label$current$width 420$title null$help_link "")
{
    global 
$lang;
    if (
is_null($title)) {
        
$title str_replace('%cvn'$name$lang['plugins-configvar']);
    }

    
// Convert stored 0–1 value to percentage for display
    
$percent round($current 100);
    
$escaped_name escape($name);
    
?>

    <div class="Question" id="question_ echo $escaped_name?>">
        <label for=" echo $escaped_name?>" title=" echo escape($title); ?>">
            
            
echo strip_tags_and_attributes($label, ['a'], ['href''target']);
            if (
$help_link !== "") {
                
render_help_link($help_link);
            }
            
?>
        </label>

        <!-- Range slider (dummy input for user interaction) -->
        <input type="range"
            id=" echo $escaped_name?>_range"
            min="1" max="100"
            value=" echo $percent?>"
            style="width: echo (int) $width?>px"
            oninput="update_ echo $escaped_name?>(this.value)" />

        <!-- Live display of percentage -->
        <span id=" echo $escaped_name?>_display"> echo $percent?>%</span>

        <!-- Actual value (0–1) for form submission -->
        <input type="hidden"
            id=" echo $escaped_name?>"
            name=" echo $escaped_name?>"
            value=" echo escape((string) $current); ?>" />

        <script>
        function update_ echo $escaped_name?>(val) {
            // Update displayed percent
            document.getElementById(' echo $escaped_name?>_display').textContent = val + '%';
            // Update hidden 0–1 value
            document.getElementById(' echo $escaped_name?>').value = (val / 100).toFixed(2);
        }
        </script>

        <div class="clearerleft"></div>
    </div>
    
}

This article was last updated 2nd April 2025 21:35 Europe/London time based on the source file dated 2nd April 2025 14:45 Europe/London time.