Home > Article > Backend Development > Example of how Smarty simply generates form elements, smarty form_PHP tutorial
This article describes an example of Smarty's simple method of generating form elements. Share it with everyone for your reference, the details are as follows:
The principle of smarty generating form elements is to give smarty an array to generate and display menus or options, and in addition, pass the value of an option for matching the default selection:
An example is as follows:
php file: 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"); ?>
Template file: 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 }>
PS: Here are several formatting/beautifying/conversion tools recommended on this site to help you sort out the messy code. I believe everyone can use it in future development:
php code online formatting and beautification tool:
http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/formatting/encryption tool:
http://tools.jb51.net/code/jscompress
Online XML formatting/compression tool:
http://tools.jb51.net/code/xmlformat
JSON code formatting and beautification tool:
http://tools.jb51.net/code/json
Online XML/JSON conversion tool:
http://tools.jb51.net/code/xmljson
JSON code online formatting/beautifying/compressing/editing/conversion tool:
http://tools.jb51.net/code/jsoncodeformat
SQL code online formatting and beautification tool:
http://tools.jb51.net/code/sqlcodeformat
Readers who are interested in more Smarty-related content can check out the special topics on this site: "Basic Tutorial for Getting Started with Smarty Templates", "Summary of PHP Template Technology", "Summary of PHP Database Operation Skills Based on PDO", "PHP Operations and Operators" Usage summary", "PHP network programming skills summary", "PHP basic syntax introductory tutorial", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "Summary of Common Database Operation Skills in PHP"
I hope this article will be helpful to everyone’s PHP program design based on smarty templates.