mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
added html_radios to distribution
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
|||||||
|
- added html_radios to distribution (Christopher Kvarme, Monte)
|
||||||
- fixed string_format modifier args (wrong order) (Paul
|
- fixed string_format modifier args (wrong order) (Paul
|
||||||
Lockaby, Monte)
|
Lockaby, Monte)
|
||||||
- use tmp file for file writes, avoid file lock race (Monte)
|
- use tmp file for file writes, avoid file lock race (Monte)
|
||||||
|
68
libs/plugins/function.html_radios.php
Normal file
68
libs/plugins/function.html_radios.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Smarty plugin
|
||||||
|
* ---------------------------------------------------------------------------------------------
|
||||||
|
* Type: function
|
||||||
|
* Name: html_radios
|
||||||
|
* Purpose: Prints the list of <input type="radio" tags generated from the passed parameters
|
||||||
|
* Parameters: name [required]- string
|
||||||
|
* checked [optional]- string
|
||||||
|
* values [required] - array
|
||||||
|
* separator[optional] - ie <br> or
|
||||||
|
* output[optional] -without this one the buttons don't have names
|
||||||
|
* Author: Christopher Kvarme <christopher.kvarme@flashjab.com>
|
||||||
|
* ---------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
function smarty_function_html_radios($params, &$smarty)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
|
||||||
|
$html_result = '';
|
||||||
|
|
||||||
|
settype($checked, 'array');
|
||||||
|
if (isset($radios)) {
|
||||||
|
settype($radios, 'array');
|
||||||
|
foreach ($radios as $key => $value) {
|
||||||
|
$html_result .= smarty_function_html_radios_optoutput($key, $value, $checked);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
settype($output, 'array');
|
||||||
|
settype($values, 'array');
|
||||||
|
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) {
|
||||||
|
if ($i < count($values)) {
|
||||||
|
$html_result .= smarty_function_html_radios_optoutput($values[$i], $output[$i], $checked, $name, $separator);
|
||||||
|
} else {
|
||||||
|
$html_result .= smarty_function_html_radios_optoutput($output[$i], $output[$i], $checked, $name, $separator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function smarty_function_html_radios_optoutput($key, $value, $checked, $name, $separator) {
|
||||||
|
if(!is_array($value)) {
|
||||||
|
$html_result = '<input type="radio" name="' . htmlspecialchars($name) . '" value="' .
|
||||||
|
htmlspecialchars($key) . '"';
|
||||||
|
if (in_array($key, $checked))
|
||||||
|
$html_result .= " checked";
|
||||||
|
$html_result .= '>' . htmlspecialchars($value) . $separator . "\n";
|
||||||
|
} else {
|
||||||
|
$html_result = smarty_function_html_radios_optgroup($key, $value, $checked, $name, $separator);
|
||||||
|
}
|
||||||
|
return $html_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function smarty_function_html_radios_optgroup($key, $values, $checked) {
|
||||||
|
$optgroup_html = '<optgroup label="' . htmlspecialchars($value) . '">' . "\n";
|
||||||
|
foreach ($values as $key => $value) {
|
||||||
|
$optgroup_html .= smarty_function_html_radios_optoutput($key, $value, $checked);
|
||||||
|
}
|
||||||
|
$optgroup_html .= "</optgroup>\n";
|
||||||
|
return $optgroup_html;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set expandtab: */
|
||||||
|
|
||||||
|
?>
|
Reference in New Issue
Block a user