mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-03 05:41:37 +01:00
html_options, html_checkboxes and html_radios now pass-thru all unknown paramters
This commit is contained in:
@@ -22,42 +22,75 @@
|
||||
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
require_once $this->_get_plugin_filepath('shared','escape_special_chars');
|
||||
function smarty_function_html_radios($params, &$smarty)
|
||||
{
|
||||
extract($params);
|
||||
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
|
||||
|
||||
$_html_result = '';
|
||||
if(!isset($name)){
|
||||
$name = 'radio';
|
||||
}
|
||||
settype($checked, 'array');
|
||||
if (isset($radios)) {
|
||||
settype($radios, 'array');
|
||||
foreach ($radios as $_key => $_val) {
|
||||
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $separator);
|
||||
}
|
||||
} else {
|
||||
settype($output, 'array');
|
||||
settype($values, 'array');
|
||||
for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) {
|
||||
$_html_result .= smarty_function_html_radios_output($name, $values[$_i], $output[$_i], $checked, $separator);
|
||||
}
|
||||
}
|
||||
$name = 'radio';
|
||||
$values = null;
|
||||
$radios = null;
|
||||
$checked = null;
|
||||
$separator = '';
|
||||
$output = null;
|
||||
$extra = '';
|
||||
|
||||
foreach($params as $_key => $_val) {
|
||||
switch($_key) {
|
||||
case 'name':
|
||||
case 'separator':
|
||||
case 'checked':
|
||||
$$_key = (string)$_val;
|
||||
break;
|
||||
|
||||
return $_html_result;
|
||||
case 'radios':
|
||||
$$_key = (array)$_val;
|
||||
break;
|
||||
|
||||
case 'values':
|
||||
case 'output':
|
||||
$$_key = array_values((array)$_val);
|
||||
break;
|
||||
|
||||
default:
|
||||
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($radios) && !isset($values))
|
||||
return ''; /* raise error here? */
|
||||
|
||||
$_html_result = '';
|
||||
|
||||
if (isset($radios) && is_array($radios)) {
|
||||
|
||||
foreach ((array)$radios as $_key=>$_val)
|
||||
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $extra, $separator);
|
||||
|
||||
} else {
|
||||
|
||||
foreach ((array)$values as $_i=>$_key) {
|
||||
$_val = isset($output[$_i]) ? $output[$_i] : '';
|
||||
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $extra, $separator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $_html_result;
|
||||
|
||||
}
|
||||
|
||||
function smarty_function_html_radios_output($name, $value, $output, $checked, $separator) {
|
||||
$_output = '<input type="radio" name="' . smarty_function_escape_special_chars($name) . '" value="' . smarty_function_escape_special_chars($value) . '"';
|
||||
|
||||
if (in_array($value, $checked)) {
|
||||
$_output .= " checked=\"checked\"";
|
||||
}
|
||||
$_output .= '>' . $output . $separator . "\n";
|
||||
function smarty_function_html_radios_output($name, $value, $output, $checked, $extra, $separator) {
|
||||
$_output = '<input type="radio" name="'
|
||||
. smarty_function_escape_special_chars($name) . '" value="'
|
||||
. smarty_function_escape_special_chars($value) . '"';
|
||||
|
||||
return $_output;
|
||||
if ($value==$checked) {
|
||||
$_output .= ' checked="checked"';
|
||||
}
|
||||
$_output .= $extra . ' />' . $output . $separator . "\n";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user