10 * Smarty {html_radios} function plugin
12 * File: function.html_radios.php<br>
14 * Name: html_radios<br>
15 * Date: 24.Feb.2003<br>
16 * Purpose: Prints out a list of radio input types<br>
18 * - name (optional) - string default "radio"
19 * - values (required) - array
20 * - options (optional) - associative array
21 * - checked (optional) - array default not set
22 * - separator (optional) - ie <br> or
23 * - output (optional) - the output next to each radio button
24 * - assign (optional) - assign the output as an array to this variable
27 * {html_radios values=$ids output=$names}
28 * {html_radios values=$ids name='box' separator='<br>' output=$names}
29 * {html_radios values=$ids checked=$checked separator='<br>' output=$names}
31 * @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
32 * (Smarty online manual)
33 * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
34 * @author credits to Monte Ohrt <monte at ohrt dot com>
39 * @uses smarty_function_escape_special_chars()
41 function smarty_function_html_radios($params, &$smarty)
43 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
55 foreach($params as $_key => $_val) {
59 $
$_key = (string)$_val;
65 $smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING
);
67 $selected = (string)$_val;
77 $
$_key = (array)$_val;
82 $
$_key = array_values((array)$_val);
86 $smarty->trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING
);
87 $options = (array)$_val;
94 if(!is_array($_val)) {
95 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
97 $smarty->trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE
);
103 if (!isset($options) && !isset($values))
104 return ''; /* raise error here? */
106 $_html_result = array();
108 if (isset($options)) {
110 foreach ($options as $_key=>$_val)
111 $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
115 foreach ($values as $_i=>$_key) {
116 $_val = isset($output[$_i]) ?
$output[$_i] : '';
117 $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
122 if(!empty($params['assign'])) {
123 $smarty->assign($params['assign'], $_html_result);
125 return implode("\n",$_html_result);
130 function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) {
134 $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!', '_', $name . '_' . $value));
135 $_output .= '<label for="' . $_id . '">';
137 $_output .= '<label>';
140 $_output .= '<input type="radio" name="'
141 . smarty_function_escape_special_chars($name) . '" value="'
142 . smarty_function_escape_special_chars($value) . '"';
144 if ($labels && $label_ids) $_output .= ' id="' . $_id . '"';
146 if ((string)$value==$selected) {
147 $_output .= ' checked="checked"';
149 $_output .= $extra . ' />' . $output;
150 if ($labels) $_output .= '</label>';
151 $_output .= $separator;
This page took 0.848408 seconds and 4 git commands to generate.