add assign attribute to html_checkboxes and html_radios

This commit is contained in:
mohrt
2004-07-02 14:14:30 +00:00
parent de676ea589
commit 8e621339e9
4 changed files with 29 additions and 13 deletions

6
NEWS
View File

@@ -1,3 +1,9 @@
- add assign attribute to html_checkboxes and html_radios
(pcg, Monte)
- remove non-xhtml conformant tag from mailto function
(tacker, Monte)
- handle date_format codes %e, %T and %D for windows (tip,
Monte)
- fix unnecessary call to smarty_core_get_include_path() inside - fix unnecessary call to smarty_core_get_include_path() inside
Smarty::_get_auto_filename() (c960657, messju) Smarty::_get_auto_filename() (c960657, messju)
- add error-messages when anything else than an identifier is passed - add error-messages when anything else than an identifier is passed

View File

@@ -20,7 +20,8 @@
* - options (optional) - associative array * - options (optional) - associative array
* - checked (optional) - array default not set * - checked (optional) - array default not set
* - separator (optional) - ie <br> or &nbsp; * - separator (optional) - ie <br> or &nbsp;
* - output (optional) - without this one the buttons don't have names * - output (optional) - the output next to each checkbox
* - assign (optional) - assign the output as an array to this variable
* Examples: * Examples:
* <pre> * <pre>
* {html_checkboxes values=$ids output=$names} * {html_checkboxes values=$ids output=$names}
@@ -95,23 +96,27 @@ function smarty_function_html_checkboxes($params, &$smarty)
return ''; /* raise error here? */ return ''; /* raise error here? */
settype($selected, 'array'); settype($selected, 'array');
$_html_result = ''; $_html_result = array();
if (is_array($options)) { if (is_array($options)) {
foreach ($options as $_key=>$_val) foreach ($options as $_key=>$_val)
$_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
} else { } else {
foreach ($values as $_i=>$_key) { foreach ($values as $_i=>$_key) {
$_val = isset($output[$_i]) ? $output[$_i] : ''; $_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
} }
} }
return $_html_result; if(!empty($params['assign'])) {
$smarty->assign($params['assign'], $_html_result);
} else {
return implode("\n",$_html_result);
}
} }
@@ -127,7 +132,7 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
} }
$_output .= $extra . ' />' . $output; $_output .= $extra . ' />' . $output;
if ($labels) $_output .= '</label>'; if ($labels) $_output .= '</label>';
$_output .= $separator . "\n"; $_output .= $separator;
return $_output; return $_output;
} }

View File

@@ -20,7 +20,8 @@
* - options (optional) - associative array * - options (optional) - associative array
* - checked (optional) - array default not set * - checked (optional) - array default not set
* - separator (optional) - ie <br> or &nbsp; * - separator (optional) - ie <br> or &nbsp;
* - output (optional) - without this one the buttons don't have names * - output (optional) - the output next to each radio button
* - assign (optional) - assign the output as an array to this variable
* Examples: * Examples:
* <pre> * <pre>
* {html_radios values=$ids output=$names} * {html_radios values=$ids output=$names}
@@ -98,23 +99,27 @@ function smarty_function_html_radios($params, &$smarty)
if (!isset($options) && !isset($values)) if (!isset($options) && !isset($values))
return ''; /* raise error here? */ return ''; /* raise error here? */
$_html_result = ''; $_html_result = array();
if (isset($options) && is_array($options)) { if (isset($options) && is_array($options)) {
foreach ((array)$options as $_key=>$_val) foreach ((array)$options as $_key=>$_val)
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels); $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
} else { } else {
foreach ((array)$values as $_i=>$_key) { foreach ((array)$values as $_i=>$_key) {
$_val = isset($output[$_i]) ? $output[$_i] : ''; $_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels); $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
} }
} }
return $_html_result; if(!empty($params['assign'])) {
$smarty->assign($params['assign'], $_html_result);
} else {
return implode("\n",$_html_result);
}
} }
@@ -130,7 +135,7 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
} }
$_output .= $extra . ' />' . $output; $_output .= $extra . ' />' . $output;
if ($labels) $_output .= '</label>'; if ($labels) $_output .= '</label>';
$_output .= $separator . "\n"; $_output .= $separator;
return $_output; return $_output;
} }

View File

@@ -105,7 +105,7 @@ function smarty_function_mailto($params, &$smarty)
$js_encode .= '%' . bin2hex($string[$x]); $js_encode .= '%' . bin2hex($string[$x]);
} }
return '<script type="text/javascript" language="javascript">eval(unescape(\''.$js_encode.'\'))</script>'; return '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>';
} elseif ($encode == 'hex') { } elseif ($encode == 'hex') {