mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-04 08:10:55 +02:00
62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Smarty plugin
|
|
* -------------------------------------------------------------
|
|
* File: function.html_radios.php
|
|
* Type: function
|
|
* Name: html_radios
|
|
* Version: 1.0
|
|
* Date: 24.Feb.2003
|
|
* Purpose: Prints out a list of radio button input types
|
|
* Input: name (optional) - string default "radio"
|
|
* values (required) - array
|
|
* checked (optional) - array default not set
|
|
* separator (optional) - ie <br> or
|
|
* output (optional) - without this one the buttons don't have names
|
|
* Author: Christopher Kvarme <christopher.kvarme@flashjab.com>
|
|
* Credits: Monte Ohrt <monte@ispi.net>
|
|
* Examples: {html_radios values=$ids output=$names}
|
|
* {html_radios values=$ids name='choices' separator='<br>' output=$names}
|
|
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
|
|
* -------------------------------------------------------------
|
|
*/
|
|
function smarty_function_html_radios($params, &$smarty)
|
|
{
|
|
extract($params);
|
|
|
|
$_html_result = '';
|
|
if(!isset($name)){
|
|
$name = 'radio';
|
|
}
|
|
settype($checked, 'array');
|
|
if (isset($radios)) {
|
|
settype($radios, 'array');
|
|
foreach ($radios as $_key => $_val) {
|
|
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $separator);
|
|
}
|
|
} else {
|
|
settype($output, 'array');
|
|
settype($values, 'array');
|
|
for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) {
|
|
$_html_result .= smarty_function_html_radios_output($name, $values[$_i], $output[$_i], $checked, $separator);
|
|
}
|
|
}
|
|
|
|
return $_html_result;
|
|
}
|
|
|
|
function smarty_function_html_radios_output($name, $value, $output, $checked, $separator) {
|
|
$_output = '<input type="radio" name="' . htmlspecialchars($name) . '[]' .'" value="' . htmlspecialchars($value) . '"';
|
|
|
|
if (in_array($value, $checked)) {
|
|
$_output .= " checked=\"checked\"";
|
|
}
|
|
$_output .= '>' . $name . $separator . "\n";
|
|
|
|
return $_output;
|
|
}
|
|
|
|
|
|
?>
|