summaryrefslogtreecommitdiff
path: root/libs/plugins/function.custom_select.php
blob: 95a76a63ec57312c63b6338f3bcba35eb54bfcb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
function smarty_function_custom_select($args)
{
    extract($args);
    global $params, $errors, $select_options;

    $user_val = $params[$param];
    if (is_array($user_val) && $num !== NULL) {
        $user_val = $user_val[$num];
    }

    $rtn = sprintf('<select name="%s">', $param);
    foreach ($select_options[$param] as $key => $val) {
        $rtn .= sprintf(
            '<option value="%s" %s>%s</option>',
            $key, ($key === $user_val || $val === $user_val) ? 'selected' : NULL, $val
        );
    }
    $rtn .= '</select>';

    if ($errors[$param]) {
        $rtn .= '<p class="check_error">'.
                '<span class="error">Error</span> '. $errors[$param].
                '</p>';
    }

    echo $rtn;
}