本文實(shí)例講述了Smarty簡(jiǎn)單生成表單元素的方法。分享給大家供大家參考,具體如下:
smarty生成表單元素功能實(shí)現(xiàn)的原理是:給smarty一個(gè)數(shù)組,用于生成和顯示菜單或選項(xiàng),另外在傳遞一個(gè)選項(xiàng)的值,用于默認(rèn)選擇的匹配:
示例如下:
php文件:index.php
<?php
include("smarty_inc.php");
$smarty->assign('cust_ids',array(1000,1001,1002,1003));
$smarty->assign('cust_names',array('丁慶','閆磊','呂東','宋子健'));
$smarty->assign('customer_id',1003);
$smarty->display("index.html");
?>
模板文件:index.html
<select name=customer_id onkeypress="">
<{html_options values=$cust_ids selected=$customer_id output=$cust_names}>
</select>
<hr />
<{html_radios name="id" values=$cust_ids selected=$customer_id output=$cust_names }>
希望本文所述對(duì)大家基于smarty模板的PHP程序設(shè)計(jì)有所幫助。