Smarty a simple way to generate a FORM element _php example

Source: Internet
Author: User
Tags php template smarty template

The examples in this article describe a method for smarty simple generation of form elements. Share to everyone for your reference, specific as follows:

The principle of smarty generating form element functionality is to give Smarty an array for generating and displaying menus or options, and for passing the value of an option to match the default selection:

Examples are 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 (' Dingqing ', ' Len Lei ', ' Lu Dong ', ' Song Zijian '));
$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>
 
 

PS: Here recommend a few of the site's format/landscaping/conversion tools to help you organize the messy code, I believe that we can use in future development:

PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat

JavaScript code Landscaping/compression/formatting/encryption Tools:
http://tools.jb51.net/code/jscompress

Online XML format/compression tools:
Http://tools.jb51.net/code/xmlformat

JSON Code Formatting Landscaping tool:
Http://tools.jb51.net/code/json

Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson

JSON code online Format/beautify/compress/edit/Convert tools:
Http://tools.jb51.net/code/jsoncodeformat

SQL code Online formatting Landscaping tools:
Http://tools.jb51.net/code/sqlcodeformat

More interested in smarty related content readers can view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP Operations and Operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on Smarty template.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.