1<?php 2/** 3 * Template_Lite {html_radios} function plugin 4 * 5 * Type: function 6 * Name: radio 7 * Purpose: Creates a radio button 8 * Input: 9 * - name = the name of the radio button 10 * - value = optional value for the checkbox 11 * - checked = boolean - whether the box is checked or not 12 * Author: Paul Lockaby <paul@paullockaby.com> 13 */ 14function tpl_function_html_radios($params, &$tpl) 15{ 16 require_once("shared.escape_chars.php"); 17 $name = null; 18 $value = ''; 19 $extra = ''; 20 21 foreach($params as $_key => $_value) 22 { 23 switch($_key) 24 { 25 case 'name': 26 case 'value': 27 $$_key = $_value; 28 break; 29 default: 30 if(!is_array($_key)) 31 { 32 $extra .= ' ' . $_key . '="' . tpl_escape_chars($_value) . '"'; 33 } 34 else 35 { 36 $tpl->trigger_error("html_radio: attribute '$_key' cannot be an array"); 37 } 38 } 39 } 40 41 if (!isset($name) || empty($name)) 42 { 43 $tpl->trigger_error("html_radio: missing 'name' parameter"); 44 return; 45 } 46 47 $toReturn = '<input type="radio" name="' . tpl_escape_chars($name) . '" value="' . tpl_escape_chars($value) . '"'; 48 if (isset($checked)) 49 { 50 $toReturn .= ' checked'; 51 } 52 $toReturn .= ' ' . $extra . ' />'; 53 return $toReturn; 54} 55?>