mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
html_radios and html_checkboxes accept "selected" instead of "checked" optionally now
This commit is contained in:
2
NEWS
2
NEWS
@@ -1,3 +1,5 @@
|
|||||||
|
- made html_radios and html_checkboxes accept "selected" instead
|
||||||
|
of "checked" optionally. (messju)
|
||||||
- made compile_id ignored in clear_cache, made order of
|
- made compile_id ignored in clear_cache, made order of
|
||||||
auto_file_name $cache_id.$compile_id again, applied the the new
|
auto_file_name $cache_id.$compile_id again, applied the the new
|
||||||
variable-naming-scheme for cache_file_handing functions (messju)
|
variable-naming-scheme for cache_file_handing functions (messju)
|
||||||
|
@@ -29,7 +29,7 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
$name = 'checkbox';
|
$name = 'checkbox';
|
||||||
$values = null;
|
$values = null;
|
||||||
$options = null;
|
$options = null;
|
||||||
$checked = null;
|
$selected = null;
|
||||||
$separator = '';
|
$separator = '';
|
||||||
$output = null;
|
$output = null;
|
||||||
|
|
||||||
@@ -48,8 +48,12 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
|
|
||||||
case 'values':
|
case 'values':
|
||||||
case 'output':
|
case 'output':
|
||||||
case 'checked':
|
|
||||||
$$_key = array_values((array)$_val);
|
$$_key = array_values((array)$_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'checked':
|
||||||
|
case 'selected':
|
||||||
|
$selected = array_values((array)$_val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'checkboxes':
|
case 'checkboxes':
|
||||||
@@ -66,19 +70,19 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
if (!isset($options) && !isset($values))
|
if (!isset($options) && !isset($values))
|
||||||
return ''; /* raise error here? */
|
return ''; /* raise error here? */
|
||||||
|
|
||||||
settype($checked, 'array');
|
settype($selected, 'array');
|
||||||
$_html_result = '';
|
$_html_result = '';
|
||||||
|
|
||||||
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, $checked, $extra, $separator);
|
$_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator);
|
||||||
|
|
||||||
|
|
||||||
} 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, $checked, $extra, $separator);
|
$_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -87,12 +91,12 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_function_html_checkboxes_output($name, $value, $output, $checked, $extra, $separator) {
|
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator) {
|
||||||
$_output = '<input type="checkbox" name="'
|
$_output = '<input type="checkbox" name="'
|
||||||
. smarty_function_escape_special_chars($name) . '[]" value="'
|
. smarty_function_escape_special_chars($name) . '[]" value="'
|
||||||
. smarty_function_escape_special_chars($value) . '"';
|
. smarty_function_escape_special_chars($value) . '"';
|
||||||
|
|
||||||
if (in_array($value, $checked)) {
|
if (in_array($value, $selected)) {
|
||||||
$_output .= ' checked="checked"';
|
$_output .= ' checked="checked"';
|
||||||
}
|
}
|
||||||
$_output .= $extra . ' />' . $output . $separator . "\n";
|
$_output .= $extra . ' />' . $output . $separator . "\n";
|
||||||
|
@@ -29,7 +29,7 @@ function smarty_function_html_radios($params, &$smarty)
|
|||||||
$name = 'radio';
|
$name = 'radio';
|
||||||
$values = null;
|
$values = null;
|
||||||
$options = null;
|
$options = null;
|
||||||
$checked = null;
|
$selected = null;
|
||||||
$separator = '';
|
$separator = '';
|
||||||
$output = null;
|
$output = null;
|
||||||
$extra = '';
|
$extra = '';
|
||||||
@@ -38,11 +38,15 @@ function smarty_function_html_radios($params, &$smarty)
|
|||||||
switch($_key) {
|
switch($_key) {
|
||||||
case 'name':
|
case 'name':
|
||||||
case 'separator':
|
case 'separator':
|
||||||
|
$$_key = (string)$_val;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'checked':
|
case 'checked':
|
||||||
|
case 'selected':
|
||||||
if(is_array($_val)) {
|
if(is_array($_val)) {
|
||||||
$smarty->trigger_error('html_radios: the "checked" attribute cannot be an array', E_USER_WARNING);
|
$smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
|
||||||
} else {
|
} else {
|
||||||
$$_key = (string)$_val;
|
$selected = (string)$_val;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -75,13 +79,13 @@ function smarty_function_html_radios($params, &$smarty)
|
|||||||
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, $checked, $extra, $separator);
|
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator);
|
||||||
|
|
||||||
} 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, $checked, $extra, $separator);
|
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -90,12 +94,12 @@ function smarty_function_html_radios($params, &$smarty)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_function_html_radios_output($name, $value, $output, $checked, $extra, $separator) {
|
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator) {
|
||||||
$_output = '<input type="radio" name="'
|
$_output = '<input type="radio" name="'
|
||||||
. smarty_function_escape_special_chars($name) . '" value="'
|
. smarty_function_escape_special_chars($name) . '" value="'
|
||||||
. smarty_function_escape_special_chars($value) . '"';
|
. smarty_function_escape_special_chars($value) . '"';
|
||||||
|
|
||||||
if ($value==$checked) {
|
if ($value==$selected) {
|
||||||
$_output .= ' checked="checked"';
|
$_output .= ' checked="checked"';
|
||||||
}
|
}
|
||||||
$_output .= $extra . ' />' . $output . $separator . "\n";
|
$_output .= $extra . ' />' . $output . $separator . "\n";
|
||||||
|
Reference in New Issue
Block a user