{html_radios}
{html_radios}
是一个创建 HTML 单选按钮组的 自定义函数。它还处理默认情况下选择哪一项。
属性
属性名称 | 必需项 | 说明 |
---|---|---|
name | 否 | 单选列表名称 |
values | 是,除非使用 options 属性 | 单选按钮值的数组 |
output | 是,除非使用 options 属性 | 单选按钮输出的数组 |
selected | 否 | 选中的单选元素 |
options | 是,除非使用 values 和 output | 值和输出的关联数组 |
separator | 否 | 分隔每个单选项目的文本字符串 |
assign | 否 | 将单选标签分配给数组而不是输出 |
labels | 否 | 添加 |
label_ids | 否 | 将 id 属性添加到 <label> 和 <input> 输出(默认为假) |
escape | 否 | 转义输出/内容(值始终转义)(默认为真) |
strict | 否 | 将使“额外”属性已禁用和只读仅在它们分别提供布尔真或字符串“已禁用”和“只读”的情况下设置(默认为假) |
-
必需属性是
values
和output
,除非改为使用options
。 -
所有输出都符合 XHTML 标准。
-
不在上述列表中的所有参数都作为 name/value-pairs 输出在所创建的每个
<input>
-tags 中。
示例
<?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_radios name='id' values=$cust_ids output=$cust_names
selected=$customer_id separator='<br />'}
<?php
$smarty->assign('cust_radios', array(
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown'));
$smarty->assign('customer_id', 1001);
模板为
两个示例都将输出
<label><input type="radio" name="id" value="1000" />Joe Schmoe</label><br />
<label><input type="radio" name="id" value="1001" checked="checked" />Jack Smith</label><br />
<label><input type="radio" name="id" value="1002" />Jane Johnson</label><br />
<label><input type="radio" 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, name, email, contact_type_id '
.'from contacts where contact_id='.$contact_id;
$smarty->assign('contact',$db->getRow($sql));
从上述数据库分配的变量将使用模板输出
{html_radios name='contact_type_id' options=$contact_types
selected=$contact.contact_type_id separator='<br />'}
另外请参阅 {html_checkboxes}
和 {html_options}