Files
smarty/libs/plugins/function.html_radios.php

64 lines
2.2 KiB
PHP
Raw Normal View History

2003-02-24 15:36:34 +00:00
<?php
/*
* Smarty plugin
2003-02-24 21:10:01 +00:00
* -------------------------------------------------------------
* File: function.html_radios.php
* Type: function
* Name: html_radios
* Version: 1.0
* Date: 24.Feb.2003
* Purpose: Prints out a list of radio input types
2003-02-24 21:10:01 +00:00
* Input: name (optional) - string default "radio"
* values (required) - array
* radios (optional) - associative array
2003-02-24 21:10:01 +00:00
* checked (optional) - array default not set
* separator (optional) - ie <br> or &nbsp;
* 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='box' separator='<br>' output=$names}
2003-02-24 21:10:01 +00:00
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
* -------------------------------------------------------------
2003-02-24 15:36:34 +00:00
*/
require_once $this->_get_plugin_filepath('shared','escape_special_chars');
2003-02-24 15:36:34 +00:00
function smarty_function_html_radios($params, &$smarty)
{
extract($params);
2003-02-24 21:10:01 +00:00
$_html_result = '';
if(!isset($name)){
2003-02-24 21:10:01 +00:00
$name = 'radio';
}
2003-02-24 15:36:34 +00:00
settype($checked, 'array');
if (isset($radios)) {
settype($radios, 'array');
2003-02-24 21:10:01 +00:00
foreach ($radios as $_key => $_val) {
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $separator);
2003-02-24 15:36:34 +00:00
}
} else {
settype($output, 'array');
settype($values, 'array');
2003-02-24 21:10:01 +00:00
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);
2003-02-24 15:36:34 +00:00
}
}
2003-02-24 21:10:01 +00:00
return $_html_result;
2003-02-24 15:36:34 +00:00
}
2003-02-24 21:10:01 +00:00
function smarty_function_html_radios_output($name, $value, $output, $checked, $separator) {
$_output = '<input type="radio" name="' . smarty_function_escape_special_chars($name) . '" value="' . smarty_function_escape_special_chars($value) . '"';
2003-02-24 21:10:01 +00:00
if (in_array($value, $checked)) {
$_output .= " checked=\"checked\"";
2003-02-24 15:36:34 +00:00
}
$_output .= '>' . $output . $separator . "\n";
2003-02-24 15:36:34 +00:00
2003-02-24 21:10:01 +00:00
return $_output;
2003-02-24 15:36:34 +00:00
}
?>