html_checkboxes

PHP Smarty

Smarty - the compiling PHP template engine
Smarty - php 模板编译引擎
Prev 来源:PHP中文社区 Chapter 8. Custom Functions[第八章.自定义函数] Next

html_checkboxes

Attribute Name Type Required Default Description
name string No checkbox name of checkbox list
values array Yes, unless using options attribute n/a an array of values for checkbox buttons
output array Yes, unless using options attribute n/a an array of output for checkbox buttons
selected string/array No empty the checked checkbox element(s)
options associative array Yes, unless using values and output n/a an associative array of values and output
separator string No empty string of text to separate each checkbox item
labels boolean No true add <label>-tags to the output

属性 类型 是否必须 缺省值 描述
name string No checkbox 复选按钮组的名称
values array Yes, 或指定 options 属性 n/a 包含复选按钮组值的数组
output array Yes, 或指定 options 属性 n/a 包含复选按钮组显示值的数组
selected string/array No empty 已选定的元素或元素数组
options associative array Yes,或指定 values 属性 n/a 包含值和显示的关联数组
separator string No empty 分隔每个复选按钮的字符串
labels boolean No true 是否为每个复选按钮添加 <label> 标签
index.php:

require('Smarty.class.php');
$smarty = new Smarty;
$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);
$smarty->display('index.tpl');


index.tpl:

{html_checkboxes values=$cust_ids checked=$customer_id output=$cust_names separator="<br />"}


index.php:

require('Smarty.class.php');
$smarty = new Smarty;
$smarty->assign('cust_checkboxes', array(
			1000 => 'Joe Schmoe',
			1001 => 'Jack Smith',
			1002 => 'Jane Johnson',
			1003 => 'Charlie Brown'));
$smarty->assign('customer_id', 1001);
$smarty->display('index.tpl');

index.tpl:

{html_checkboxes name="id" options=$cust_checkboxes checked=$customer_id separator="<br />"}


OUTPUT: (both examples)

<label><input type="checkbox" name="checkbox[]" value="1000" />Joe Schmoe</label><br />
<label><input type="checkbox" name="checkbox[]" value="1001" checked="checked" />Jack Smith</label><br />
<label><input type="checkbox" name="checkbox[]" value="1002" />Jane Johnson</label><br />
<label><input type="checkbox" name="checkbox[]" value="1003" />Charlie Brown</label><br />

Prev 来源:PHP中文社区 Home Next
fetch Up html_image