Skip to content

{html_radios}

{html_radios} 是一个自定义函数,用于创建 HTML 单选按钮组。它还会处理默认情况下选择的项目。

属性

属性名 必需 描述
name 单选按钮列表的名称
values 单选按钮的值的数组
output 单选按钮的输出的数组
selected 选中的单选按钮元素
options 值和输出的关联数组
separator 用于分隔每个单选项的文本字符串
assign 将单选标签分配给数组而不是输出
labels
label_ids 将 id 属性添加到
escape 转义输出/内容(值始终会被转义)(默认为 true)
strict 如果提供了布尔值 TRUE 或字符串 "disabled""readonly",则只会设置 "extra" 属性 disabledreadonly(默认为 false)
  • 必需的属性是 valuesoutput,除非使用 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_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);

模板如下:

{html_radios name='id' options=$cust_radios
     selected=$customer_id separator='<br />'}

这两个示例的输出将是:

<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}