{ html_checkboxes}
{html_checkboxes}
是一个 自定义函数,它使用提供的创建 HTML 复选框组数据。它还关照项目默认选中的方式。
属性
属性名称 | 必需 | 描述 |
---|---|---|
name | 否 | 复选框列表名称(默认为“checkbox”) |
values | 是,除非使用选项属性 | 复选框按钮值数组 |
output | 是,除非使用选项属性 | 复选框按钮显示内容数组 |
selected | 否 | 被选中的复选框元素,字符串或数组 |
options | 是,除非使用值和显示内容 | 值和显示内容的关联数组 |
separator | 否 | 用于分隔每个复选框项目的文本字符串 |
assign | 否 | 将复选框标记分配给数组,而不是输出 |
labels | 否 | 在显示内容中添加 <label>-标记(默认为 true) |
label_ids | 否 | 在显示内容中为 <label> 和 <input> 添加 id-属性(默认为 false) |
escape | 否 | 转义显示内容/内容(值总是转义的)(默认为 true) |
strict | 否 | 将“额外”属性disabled和readonly设置为仅在提供布尔型TRUE或字符串“disabled”和“readonly”时设置(默认为false) |
-
必需属性为
values
和output
,除非您使用options
替代。 -
所有输出均符合XHTML。
-
以上列表中没有的所有参数均以名称/值对的形式打印在每个已创建的<input>-标签中。
示例
<?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',
[
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown',
]
);
$smarty->assign('customer_id', 1001);
模板是
两个示例都将输出
<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 />
<?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));
以上数据库查询的结果将输出为。