本文實例講述了Smarty簡單生成表單元素的方法。分享給大家供大家參考,具體如下:
smarty生成表單元素功能實現的原理是:給smarty一個數組,用于生成和顯示菜單或選項,另外在傳遞一個選項的值,用于默認選擇的匹配:
示例如下:
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 }>