Get Smarty


Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Shop for 2018 World Cup Football Boots Online sale at

Browse best 2018 world cup soccer cleats and shoes from



{html_radios}是一个 自定义函数,用于创建HTML的单选框组和提供数据。 请注意默认选中的情况。

参数名称 类型 必选参数 默认值 说明
name string No radio 单选框的名称
values array 必选,除非使用options属性 n/a 单选框的值数据
output array 必选,除非使用options属性 n/a 单选框的显示数据
selected string No empty 选中的项
options 数组 必须, 除非使用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 将输出中的/转换(值总是会被转换)
  • 必须赋值的属性是valuesoutput, 除非使用options来代替。

  • 全部的输出标签都遵循XHTML规则。

  • 任何不在上面列表中的键值对属性,都会被输出到<input>标签中作为属性和值。

Example 8.13. {html_radios}第一个例子


$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 />'}

Example 8.14. {html_radios}第二个例子


$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 />


Example 8.15. {html_radios} 数据库例子(如 PEAR 或 ADODB):


$sql = 'select type_id, types from contact_types order by type';

$sql = 'select contact_id, name, email, contact_type_id '
        .'from contacts where contact_id='.$contact_id;




{html_radios name='contact_type_id' options=$contact_types
     selected=$contact.contact_type_id separator='<br />'}



No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 12 plus 6? (Are you human?)