Get Smarty

Donate

Paypal

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

Advertisement

{html_radios}

{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}第一个例子


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

Example 8.14. {html_radios}第二个例子


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

  

Example 8.15. {html_radios} 数据库例子(如 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, 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}

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors