{html_checkboxes}是一个
   自定义函数,用于创建HTML的多选框组和提供数据。
   请注意默认选中的情况。
   
| 参数名称 | 类型 | 必选参数 | 默认值 | 说明 | 
|---|---|---|---|---|
| name | string | No | checkbox | 多选框的名称 | 
| values | array | 必选,除非使用options属性 | n/a | 多选框的值数据 | 
| output | array | 必选,除非使用options属性 | n/a | 多选框的显示数据 | 
| selected | string/array | No | empty | 选中的项(一个或多个) | 
| options | associative array | 必须, 除非使用values 和 output属性 | n/a | 多选框的值-显示的数组 | 
| separator | string | No | empty | 字符串中分隔每项的字符 | 
| assign | string | No | empty | 将多选框标签赋值到数组,而不是输出 | 
| labels | boolean | No | TRUE | 
在输出中增加<label>标签 | 
| label_ids | boolean | No | FALSE | 
给<label> 和 <input>设置ID属性 | 
| escape | boolean | No | TRUE | 
将输出中的/转换(值总是会被转换) | 
   必须赋值的属性是values 和
   output, 除非使用options来代替。
   
全部的输出标签都遵循XHTML规则。
任何不在上面列表中的键值对属性,都会被输出到<input>标签中作为属性和值。
Example 8.6. {html_checkboxes}
<?php
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
$smarty->assign('cust_names', array(
                                'Joe Schmoe',
                                'Jack Smith',
                                'Jane Johnson',
                                'Charlie Brown')
                              );
$smarty->assign('customer_id', 1001);
?>
  
模板是:
{html_checkboxes name='id' values=$cust_ids output=$cust_names
   selected=$customer_id  separator='<br />'}
  
或者PHP代码:
<?php
$smarty->assign('cust_checkboxes', array(
                                     1000 => 'Joe Schmoe',
                                     1001 => 'Jack Smith',
                                     1002 => 'Jane Johnson',
                                     1003 => 'Charlie Brown')
                                   );
$smarty->assign('customer_id', 1001);
?>
  
模板是:
{html_checkboxes name='id' options=$cust_checkboxes
   selected=$customer_id separator='<br />'}
  
上面两个例子的输出:
<label><input type="checkbox" name="id[]" value="1000" />Joe Schmoe</label><br /> <label><input type="checkbox" name="id[]" value="1001" checked="checked" />Jack Smith</label> <br /> <label><input type="checkbox" name="id[]" value="1002" />Jane Johnson</label><br /> <label><input type="checkbox" name="id[]" value="1003" />Charlie Brown</label><br />
Example 8.7. 数据库例子(例如 PEAR 或 ADODB):
<?php
$sql = 'select type_id, types from contact_types order by type';
$smarty->assign('contact_types',$db->getAssoc($sql));
$sql = 'select contact_id, contact_type_id, contact '
       .'from contacts where contact_id=12';
$smarty->assign('contact',$db->getRow($sql));
?>
  
输出:
{html_checkboxes name='contact_type_id' options=$contact_types
        selected=$contact.contact_type_id separator='<br />'}