enhancing html_checkboxes
| From: | Tom Anderson | Date: | Wed, 07 May 2003 18:04:16 +0000 |
| Subject: | enhancing html_checkboxes | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-1413@lists.php.net to get a copy of this message | ||
I ran into an issue which I solved by enhancing html_checkboxes. My
problem: I wanted checkboxes like this:
[] one [] two
[] three [] four
html_checkboxes has separator for individual boxes but I wanted to break on
groups too.
The edited code is below. I can submit a complete diff if anyone is
interested in merging this into the main smarty code. New usage:
{html_checkboxes name="checkboxes" options=$checkboxes separator=" "
breaks=1 breakseparator="<BR>"}
Thanks,
Tom
1st, I check for 'breaks' and 'breakseparator' and put them in local vars
the same way name and separator are handled. Next, I replaced:
if (is_array($options)) {
foreach ($options as $_key=>$_val)
$_html_result .= smarty_function_html_checkboxes_output($name,
$_key, $_val, $selected, $extra, $separator);
} else {
with:
if (is_array($options)) {
$_loopcount = 0;
$_breakpoint = (int)(sizeof($options) / ++$breaks); // logical to
say 1 break but math = /2 for 1 break.
$_breakcount = 1;
foreach ($options as $_key=>$_val) {
$_html_result .= smarty_function_html_checkboxes_output($name,
$_key, $_val, $selected, $extra, $separator);
// If $breaks, seperate the checkboxes by groups by $breakseparator
if ($breaks) {
if ($_breakcount < $breaks && (++$_loopcount ==
($_breakpoint * $_breakcount))) {
$_html_result .= $breakseparator;
$_breakcount ++;
}
}
}
} else {