PHP+smarty对checkbox的初始化和绑定
来源:互联网 发布:上海知楚 旻泉 编辑:程序博客网 时间:2024/06/07 10:11
在PHP+smarty中对checkbox进行加载时候,和其他的不一样.smarty有自带的checkbox自定义函数html_checkboxes.具体实现如下:
从接口取出数据绑定到checkbox:
第一种:
php:
//默认显示的checkbox选项$responsibleDepartmentValue = array("收货组","IQC","仓储组","包货组","资料组","图片组");//从接口查出来的数据然后用逗号分割成数组$responsibleDepartmentSelectValue = array();$xxxrepsonse = $Soap->getDepartment();$responsibleDepartmentSelectValue = explode(',',$xxxrepsonse);$smarty->assign("responsibleDepartmentValue", $responsibleDepartmentValue);$smarty->assign("responsibleDepartmentSelectValue", $responsibleDepartmentSelectValue);
tpl:
{html_checkboxes name=selectResponseDepartmentCheckbox values=$responsibleDepartmentValue output=$responsibleDepartmentValue selected=$responsibleDepartmentValue separator=""}
name(用于post到后台获取数组)
values,checkbox中的value
output,checkbox中的显示字符
selected,已选定的元素
separator,checkbox之间的分隔符
labels,是否有
最后页面生成结果:
<label><input name="selectResponseDepartmentCheckbox[]" value="收货组" type="checkbox">收货组</label><label><input name="selectResponseDepartmentCheckbox[]" value="IQC" type="checkbox">IQC</label><label><input name="selectResponseDepartmentCheckbox[]" value="仓储组" type="checkbox">仓储组</label><label><input name="selectResponseDepartmentCheckbox[]" value="包货组" type="checkbox">包货组</label><label><input name="selectResponseDepartmentCheckbox[]" value="资料组" type="checkbox">资料组</label><label><input name="selectResponseDepartmentCheckbox[]" value="图片组" type="checkbox">图片组</label>
第二种:
php:
//默认显示的checkbox选项$responsibleDepartmentValue = array( [0]=>"收货组", [1]=>"IQC", [2]=>"仓储组", [3]=>"包货组", [4]=>"资料组", [5]=>"图片组" );//从接口查出来的数据然后用逗号分割成数组$responsibleDepartmentSelectValue = array();$xxxrepsonse = $Soap->getDepartment();$responsibleDepartmentSelectValue = explode(',',$xxxrepsonse);$smarty->assign("responsibleDepartmentValue", $responsibleDepartmentValue);$smarty->assign("responsibleDepartmentSelectValue", $responsibleDepartmentSelectValue);
tpl:
{html_checkboxes name=selectResponseDepartmentCheckbox options=$responsibleDepartmentValue selected=$responsibleDepartmentValue separator=""}
name,checkbox的name属性
selected,已选定的元素
options,包含值和显示的数组,可以是关联数组、也可以是数值数组
解析后的value=数组的下标,显示的字符为数组下标对应的值
separator,checkbox之间的分隔符
labels,是否有
最终页面生成结果:
<label><input name="selectResponseDepartmentCheckbox[]" value="0" type="checkbox">收货组</label><label><input name="selectResponseDepartmentCheckbox[]" value="1" type="checkbox">IQC</label><label><input name="selectResponseDepartmentCheckbox[]" value="2" type="checkbox">仓储组</label><label><input name="selectResponseDepartmentCheckbox[]" value="3" type="checkbox">包货组</label><label><input name="selectResponseDepartmentCheckbox[]" value="4" type="checkbox">资料组</label><label><input name="selectResponseDepartmentCheckbox[]" value="5" type="checkbox">图片组</label>
PHP对smarty中checkbox的选中项获取:
使用了html_checkboxes后,函数会对name进行自动生成相应的[]html,以数组的形式传给php文件.
tpl:
<form method="POST" action="/index.php">{html_checkboxes name=selectResponseDepartmentCheckbox values=$responsibleDepartmentValue output=$responsibleDepartmentValue selected=$responsibleDepartmentValue separator=""} </form>
php接收代码:
if(isset($_POST["selectResponseDepartmentCheckbox"])){ //将责任部门用逗号分割 $responsibleDepartment = implode(",",$_POST["selectResponseDepartmentCheckbox"]); }
1 0
- PHP+smarty对checkbox的初始化和绑定
- 【PHP】smarty初始化文件
- php试用smarty和ADODB实现对数据分页读取
- php的smarty循环
- php smarty的配置
- php的smarty循环
- [PHP]Smarty的使用
- PHP的Smarty
- 对RadioButton和CheckBox的一些总结
- Smarty的基本配置【smarty.inc.php】
- 关于gridview和checkbox绑定做删除功能的注意事项
- Firefox和IE的JS兼容性:关于checkbox初始化选中
- javascript+php 实现全选/全不选 以及对checkbox的处理
- php学习之smarty和zend mvc 的选择困惑
- PHP中模板的使用(phplib和smarty)
- php、smarty中格式化输出日期和时间的比较
- asp.net绑定checkboxlist--------jquery绑定click事件,获取checkbox的value和显示值
- smarty 的注意事项和smarty的安装
- bzoj2301 [HAOI2011]Problem b (莫比乌斯函数)
- javascript的基本语法
- 【水题】UVA 512 Spreadsheet Tracking
- hadoop伪分布式环境搭建
- C#MVC视图获取modle实体类中的参数
- PHP+smarty对checkbox的初始化和绑定
- C Primer Plus 第6章 C控制语句:循环 编程练习
- GPS定位\基站定位\WiFi辅助定位及其其他定位原理详解
- 如何选择 损失函数 Loss Function
- Android中获取正在运行的应用程序-----ActivityManager.RunningAppProcessInfo类详解
- JS 如何创建对象、数据类型
- SpringBoot入门系列:第一篇 Hello World
- 到底什么是BFC、IFC、GFC和FFC
- 第一个Django应用