Because the company needs to use quickform in combination with the development model of SMARTY, we have made some effort in the past few days to share with you our experiences. quickform is a PEAR class library, you can quickly generate Form Controls and verify the JS Code of the form.HTMLIsn't it very fast to generate? It's not more troublesome to use it. Indeed, a small number of form controls do not show the advantages of quickform, but if there are a large number of form controls, such as the background of OA, the advantages of quickform are shown. Quick form has the features of clear code and easy maintenance. It is very suitable for the development of large and medium-sized projects and can be easily used in smarty, ^ _ ^ let's talk a little nonsense. Let's look at the Code. However, you 'd better understand the installation of PEAR before. Refer to: idea.
Because quickform used by the company has been improved by itself, there will be some differences between the code and what you see on the Internet. It is inconvenient to describe the copyright here, and the core code will be briefly displayed, if you are interestedFriendLet's take a look at this HAOHAPPY article: http://www.phpe.net/articles/418.shtml
[Php]
<? Php
/*
* Author: Boss Hui
* Page: path. cfg. php
* Function: set the system path.
* All Rights Reserved: copy everything _^
*/
$ Global ['path'] ['conf'] = $ global ['path'] ['root']. 'conf/'; // defines the path of the system configuration file.
$ Global ['path'] ['lib'] = $ global ['path'] ['root']. 'lib/'; // defines the path of the system library file
?>
[/Php]
[Php]
<? Php
/*
* Author: Boss Hui
* Page: smarty. cfg. php
* Function: Basic smarty Configuration
* All Rights Reserved: copy everything _^
*/
// Define the template path
$ Global ['smarty '] ['template _ dir'] = $ global ['path'] ['root']. 'lib/smarty/templates ';
// Define the template compilation directory
$ Global ['smarty '] ['compile _ dir'] = $ global ['path'] ['root']. 'lib/smarty/templates_c ';
// Define the path of the smarty configuration folder
$ Global ['smarty '] ['config _ dir'] = $ global ['path'] ['conf']. 'lib/smarty/configs ';
$ Global ['smarty '] ['cache _ dir'] = $ global ['path'] ['root']. 'lib/smarty/cache ';
// $ Global ['smarty '] ['compile _ check'] = true;
// Set the smarty error to disable
$ Global ['smarty '] ['destgging'] = false;
// Disable Cache
$ Global ['smarty '] ['caching'] = false;
// $ Global ['smarty '] ['cache _ lifetime'] = 6000;
// Define the left and right boundary Operators
$ Global ['smarty '] ['left _ delimiter'] = '<{';
$ Global ['smarty '] ['right _ delimiter'] = '}> ';
?>
[/Php]
[Php]
<? Php
/*
* Author: Boss Hui
* Page: common. cfg. php
* Function: global configuration
* All Rights Reserved: copy everything _^
*/
$ Global ['path'] ['root'] = dirname (_ FILE _). '/'; // set the root directory
Require ($ global ['path'] ['conf']. 'conf/path. cfg. php ');
Require ($ global ['path'] ['conf']. 'smarty. cfg. php ');
// Contains the smarty class library
Require ($ global ['path'] ['lib']. 'smarty/libs/smarty. class. php ');
// Smarty Configuration
$ Tpl = new Smarty ();
$ Tpl-> template_dir = $ global ['smarty '] ['template _ dir'];
$ Tpl-> compile_dir = $ global ['smarty '] ['compile _ dir'];
$ Tpl-> config_dir = $ global ['smarty '] ['config _ dir'];
$ Tpl-> debugging = $ global ['smarty '] ['destgging'];
$ Tpl-> caching = $ global ['smarty '] ['caching'];
$ Tpl-> cache_lifetime = $ global ['smarty '] ['cache _ lifetime'];
$ Tpl-> left_delimiter = $ global ['smarty '] ['left _ delimiter'];
$ Tpl-> right_delimiter = $ global ['smarty '] ['right _ delimiter'];
Unset ($ global ['smarty ']);
Ini_set ('include _ path', ini_get ('include _ path ').
PATH_SEPARATOR. $ global ['path'] ['lib']. 'pear/'); // load the pear Library File
?>
[/Php]
[Php]
<? Php
/*
* Author: Boss Hui
* Page: index. php
* Function: UI
* All Rights Reserved: copy everything _^
*/
Require_once ('common. inc. php'); // load global configuration
// Contains the quickform class library
Require ($ global ['path'] ['lib']. 'pear/HTML/QuickForm. php ');
$ Form = new HTML_QuickForm ('changepwdform'); // generate a quickform instance. The parameter is the form name.
/*
* Start adding form elements
* The parameters are in sequence: form Element type, name, (Button label text), and style
*/
$ Form-> addElement ('Password', 'adminpwd', '', 'style =" width: 120px "');
$ Form-> addElement ('Password', 'newpwd', '', 'style =" width: 120px "');
$ Form-> addElement ('Password', 'newpwd2 ', '', 'style =" width: 120px "');
$ Form-> addElement ('submit ', 'btnsubmit', 'change password', 'style = "width: 100px "');
// Add verification rules to automatically generate JS
$ Form-> addRule ('adminpwd', 'the password cannot be blank! ', 'Requestred', '', 'client ');
$ Form-> addRule ('newpwd', 'the new password cannot be blank! ', 'Requestred', '', 'client ');
$ Form-> addRule ('newpwd2 ',' enter the new password again! ', 'Requestred', 'client ');
$ Form-> addRule (array ('newpwd', 'newpwd2 '), "The two passwords are inconsistent! ", 'Company','', 'client ');
$ Form->; // The form cannot be submitted.
// Allocate form data to the array
$ Tpl-> assign ('form _ data', $ form-> toArray ());
// Display template
$ Tpl-> display ('index. tpl ');
?>
[/Php]
Template code:
Copy codeThe Code is as follows:
<HTML>
<HEAD>
<TITLE> quickform + smarty </TITLE>
<{If $ form_data.w.cr =pt}>
<{$ Form_data.w.cr =pt}>
<{/If}>
</HEAD>
<BODY>
<P> </p>
<P> </p>
<P> </p>
<Form <{$ form_data.attributes}>
<Table width = "300" border = "0" align = "center" cellpadding = "3" cellspacing = "3"
Bgcolor = "# F6F6F6" style = "font-size: 9pt" class = "AddTable">
<Tr bgcolor = "# FFFFFF">
<Td width = "47%" colspan = "2"> <div align = "center"> change the administrator password </div> </tr>
<Tr>
<Tr>
<Td width = "47%"> <div align = "center"> existing administrator password
</Div> </td>
<Td width = "53%"> <{$ form_data.adminPwd.html}> </td>
</Tr>
<Tr>
<Td> <div align = "center"> New Password
</Div> </td>
<Td> <{$ form_data.newPwd.html}> </td>
</Tr>
<Tr>
<Td> <div align = "center"> enter the new password again
</Div> </td>
<Td> <{$ form_data.newPwd2.html}> </td>
</Tr>
<Tr>
<Td colspan = "2"> <div align = "center">
<{$ Form_data.btnSubmit.html}>
</Div> </td>
</Tr>
</Table>
</Form>
<Scr limit pt type = "text/javascr limit pt" src = "response. js"> </scr limit pt>
</BODY>
</HTML>
Here, we may wonder why the definition of paths is so complicated and absolute paths are used? This is recently adapted to the needs of the company's projects! In fact, this facilitates the deployment of large projects. This post is intended for beginners who have never been familiar with quickform or smarty. Of course, I am just a brief introduction here. If you are interested, I hope you can continue to study it in depth, finally, let's look at the effect:
Check whether the two passwords are the same:
[Php]
$ Form-> addRule (array ('newpwd', 'newpwd2 '), "The two passwords are inconsistent! ", 'Company','', 'client ');
[/Php]
Isn't the code concise and clear? Well, it will be applied in combination with XAJAX. I will continue to share my learning experience with you!