mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
added <labels>-support to function.html_checkboxes.php and function.html_radios.php
This commit is contained in:
4
NEWS
4
NEWS
@@ -1,3 +1,7 @@
|
|||||||
|
- added <labels> to html_checkboxes and html_radios (Philippe, messju)
|
||||||
|
- added "labels"-options to turn off labels in html_checkboxes and _radios
|
||||||
|
(messju)
|
||||||
|
|
||||||
Version 2.5.0 (April 11, 2003)
|
Version 2.5.0 (April 11, 2003)
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
|
@@ -31,10 +31,11 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
$options = null;
|
$options = null;
|
||||||
$selected = null;
|
$selected = null;
|
||||||
$separator = '';
|
$separator = '';
|
||||||
|
$labels = true;
|
||||||
$output = null;
|
$output = null;
|
||||||
|
|
||||||
$extra = '';
|
$extra = '';
|
||||||
|
|
||||||
foreach($params as $_key => $_val) {
|
foreach($params as $_key => $_val) {
|
||||||
switch($_key) {
|
switch($_key) {
|
||||||
case 'name':
|
case 'name':
|
||||||
@@ -42,6 +43,10 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
$$_key = $_val;
|
$$_key = $_val;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'labels':
|
||||||
|
$$_key = (bool)$_val;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'options':
|
case 'options':
|
||||||
$$_key = (array)$_val;
|
$$_key = (array)$_val;
|
||||||
break;
|
break;
|
||||||
@@ -76,13 +81,13 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
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);
|
$_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);
|
$_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -91,15 +96,19 @@ function smarty_function_html_checkboxes($params, &$smarty)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator) {
|
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) {
|
||||||
$_output = '<input type="checkbox" name="'
|
$_output = '';
|
||||||
|
if ($labels) $_output .= '<label>';
|
||||||
|
$_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, $selected)) {
|
if (in_array($value, $selected)) {
|
||||||
$_output .= ' checked="checked"';
|
$_output .= ' checked="checked"';
|
||||||
}
|
}
|
||||||
$_output .= $extra . ' />' . $output . $separator . "\n";
|
$_output .= $extra . ' />' . $output;
|
||||||
|
if ($labels) $_output .= '</label>';
|
||||||
|
$_output .= $separator . "\n";
|
||||||
|
|
||||||
return $_output;
|
return $_output;
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ function smarty_function_html_radios($params, &$smarty)
|
|||||||
$options = null;
|
$options = null;
|
||||||
$selected = null;
|
$selected = null;
|
||||||
$separator = '';
|
$separator = '';
|
||||||
|
$labels = true;
|
||||||
$output = null;
|
$output = null;
|
||||||
$extra = '';
|
$extra = '';
|
||||||
|
|
||||||
@@ -50,6 +51,10 @@ function smarty_function_html_radios($params, &$smarty)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'labels':
|
||||||
|
$$_key = (bool)$_val;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'options':
|
case 'options':
|
||||||
$$_key = (array)$_val;
|
$$_key = (array)$_val;
|
||||||
break;
|
break;
|
||||||
@@ -79,13 +84,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, $selected, $extra, $separator);
|
$_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);
|
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -94,15 +99,19 @@ function smarty_function_html_radios($params, &$smarty)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator) {
|
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels) {
|
||||||
$_output = '<input type="radio" name="'
|
$_output = '';
|
||||||
|
if ($labels) $_output .= '<label>';
|
||||||
|
$_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==$selected) {
|
if ($value==$selected) {
|
||||||
$_output .= ' checked="checked"';
|
$_output .= ' checked="checked"';
|
||||||
}
|
}
|
||||||
$_output .= $extra . ' />' . $output . $separator . "\n";
|
$_output .= $extra . ' />' . $output;
|
||||||
|
if ($labels) $_output .= '</label>';
|
||||||
|
$_output .= $separator . "\n";
|
||||||
|
|
||||||
return $_output;
|
return $_output;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user