- added escape argument to html_checkboxes and html_radios (Forum Topic 20425)

This commit is contained in:
rodneyrehm
2011-11-16 11:28:35 +00:00
parent 0fb537aed2
commit 3d03494a74
3 changed files with 19 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
===== trunk ===== ===== trunk =====
16.11.2011 16.11.2011
- bugfix Smarty_Resource::load() did not always return a proper resource handler (Forum Topic 20414) - bugfix Smarty_Resource::load() did not always return a proper resource handler (Forum Topic 20414)
- added escape argument to html_checkboxes and html_radios (Forum Topic 20425)
===== Smarty-3.1.5 ===== ===== Smarty-3.1.5 =====
14.11.2011 14.11.2011

View File

@@ -29,6 +29,7 @@
* - separator (optional) - ie <br> or &nbsp; * - separator (optional) - ie <br> or &nbsp;
* - output (optional) - the output next to each checkbox * - output (optional) - the output next to each checkbox
* - assign (optional) - assign the output as an array to this variable * - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true
* </pre> * </pre>
* *
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} * @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
@@ -50,6 +51,7 @@ function smarty_function_html_checkboxes($params, $template)
$options = null; $options = null;
$selected = array(); $selected = array();
$separator = ''; $separator = '';
$escape = true;
$labels = true; $labels = true;
$label_ids = false; $label_ids = false;
$output = null; $output = null;
@@ -63,6 +65,7 @@ function smarty_function_html_checkboxes($params, $template)
$$_key = (string) $_val; $$_key = (string) $_val;
break; break;
case 'escape':
case 'labels': case 'labels':
case 'label_ids': case 'label_ids':
$$_key = (bool) $_val; $$_key = (bool) $_val;
@@ -130,12 +133,12 @@ function smarty_function_html_checkboxes($params, $template)
if (isset($options)) { if (isset($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, $label_ids); $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
} }
} 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, $label_ids); $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
} }
} }
@@ -147,7 +150,7 @@ function smarty_function_html_checkboxes($params, $template)
} }
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) { function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape=true) {
$_output = ''; $_output = '';
if (is_object($value)) { if (is_object($value)) {
@@ -183,7 +186,9 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
$name = smarty_function_escape_special_chars($name); $name = smarty_function_escape_special_chars($name);
$value = smarty_function_escape_special_chars($value); $value = smarty_function_escape_special_chars($value);
$output = smarty_function_escape_special_chars($output); if ($escape) {
$output = smarty_function_escape_special_chars($output);
}
$_output .= '<input type="checkbox" name="' . $name . '[]" value="' . $value . '"'; $_output .= '<input type="checkbox" name="' . $name . '[]" value="' . $value . '"';

View File

@@ -23,6 +23,7 @@
* - separator (optional) - ie <br> or &nbsp; * - separator (optional) - ie <br> or &nbsp;
* - output (optional) - the output next to each radio button * - output (optional) - the output next to each radio button
* - assign (optional) - assign the output as an array to this variable * - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true
* </pre> * </pre>
* Examples: * Examples:
* <pre> * <pre>
@@ -50,6 +51,7 @@ function smarty_function_html_radios($params, $template)
$options = null; $options = null;
$selected = null; $selected = null;
$separator = ''; $separator = '';
$escape = true;
$labels = true; $labels = true;
$label_ids = false; $label_ids = false;
$output = null; $output = null;
@@ -77,6 +79,7 @@ function smarty_function_html_radios($params, $template)
} }
break; break;
case 'escape':
case 'labels': case 'labels':
case 'label_ids': case 'label_ids':
$$_key = (bool) $_val; $$_key = (bool) $_val;
@@ -118,12 +121,12 @@ function smarty_function_html_radios($params, $template)
if (isset($options)) { if (isset($options)) {
foreach ($options as $_key => $_val) { foreach ($options as $_key => $_val) {
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids); $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
} }
} 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_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids); $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
} }
} }
@@ -134,7 +137,7 @@ function smarty_function_html_radios($params, $template)
} }
} }
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape)
{ {
$_output = ''; $_output = '';
@@ -171,7 +174,9 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
$name = smarty_function_escape_special_chars($name); $name = smarty_function_escape_special_chars($name);
$value = smarty_function_escape_special_chars($value); $value = smarty_function_escape_special_chars($value);
$output = smarty_function_escape_special_chars($output); if ($escape) {
$output = smarty_function_escape_special_chars($output);
}
$_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"'; $_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"';