cvs: smarty / NEWS /libs/plugins function.html_checkboxes.php function.html_radios.php

From: Date: Mon, 14 Apr 2003 07:47:49 +0000
Subject: cvs: smarty / NEWS /libs/plugins function.html_checkboxes.php function.html_radios.php
Groups: php.smarty.cvs 
Request: Send a blank email to php-smarty-cvs+get-520@lists.php.net to get a copy of this message
messju Mon Apr 14 03:47:49 2003 EDT Modified files: /smarty NEWS /smarty/libs/plugins function.html_checkboxes.php function.html_radios.php Log: added <labels>-support to function.html_checkboxes.php and function.html_radios.php Index: smarty/NEWS diff -u smarty/NEWS:1.336 smarty/NEWS:1.337 --- smarty/NEWS:1.336 Fri Apr 11 11:12:11 2003 +++ smarty/NEWS Mon Apr 14 03:47:49 2003 @@ -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) ------------------------------ Index: smarty/libs/plugins/function.html_checkboxes.php diff -u smarty/libs/plugins/function.html_checkboxes.php:1.7 smarty/libs/plugins/function.html_checkboxes.php:1.8 --- smarty/libs/plugins/function.html_checkboxes.php:1.7 Fri Mar 21 03:20:12 2003 +++ smarty/libs/plugins/function.html_checkboxes.php Mon Apr 14 03:47:49 2003 @@ -31,10 +31,11 @@ $options = null; $selected = null; $separator = ''; + $labels = true; $output = null; - + $extra = ''; - + foreach($params as $_key => $_val) { switch($_key) { case 'name': @@ -42,6 +43,10 @@ $$_key = $_val; break; + case 'labels': + $$_key = (bool)$_val; + break; + case 'options': $$_key = (array)$_val; break; @@ -76,13 +81,13 @@ if (is_array($options)) { 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 { foreach ($values as $_i=>$_key) { $_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_output($name, $value, $output, $selected, $extra, $separator) { - $_output = '<input type="checkbox" name="' +function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) { + $_output = ''; + if ($labels) $_output .= '<label>'; + $_output .= '<input type="checkbox" name="' . smarty_function_escape_special_chars($name) . '[]" value="' . smarty_function_escape_special_chars($value) . '"'; if (in_array($value, $selected)) { $_output .= ' checked="checked"'; } - $_output .= $extra . ' />' . $output . $separator . "\n"; + $_output .= $extra . ' />' . $output; + if ($labels) $_output .= '</label>'; + $_output .= $separator . "\n"; return $_output; } Index: smarty/libs/plugins/function.html_radios.php diff -u smarty/libs/plugins/function.html_radios.php:1.12 smarty/libs/plugins/function.html_radios.php:1.13 --- smarty/libs/plugins/function.html_radios.php:1.12 Fri Mar 21 03:20:12 2003 +++ smarty/libs/plugins/function.html_radios.php Mon Apr 14 03:47:49 2003 @@ -31,6 +31,7 @@ $options = null; $selected = null; $separator = ''; + $labels = true; $output = null; $extra = ''; @@ -50,6 +51,10 @@ } break; + case 'labels': + $$_key = (bool)$_val; + break; + case 'options': $$_key = (array)$_val; break; @@ -79,13 +84,13 @@ if (isset($options) && is_array($options)) { 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 { foreach ((array)$values as $_i=>$_key) { $_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_output($name, $value, $output, $selected, $extra, $separator) { - $_output = '<input type="radio" name="' +function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels) { + $_output = ''; + if ($labels) $_output .= '<label>'; + $_output .= '<input type="radio" name="' . smarty_function_escape_special_chars($name) . '" value="' . smarty_function_escape_special_chars($value) . '"'; if ($value==$selected) { $_output .= ' checked="checked"'; } - $_output .= $extra . ' />' . $output . $separator . "\n"; + $_output .= $extra . ' />' . $output; + if ($labels) $_output .= '</label>'; + $_output .= $separator . "\n"; return $_output; }

« previous php.smarty.cvs (#520) next »