How to use smartprinter Smarty+QUICKFORM small demonstration
Since the company needs quickform combined with the SMARTY development model, I have been working on it in the past few days. Let me share my experience with you. Quickform is a PEAR class library that can quickly generate JS code for form controls and verification forms. You may think this is written by hand. Isn’t it fast to generate JS and HTML? Isn’t it more troublesome to use that one? Indeed, a small number of form controls cannot show the advantages of quickform, but if there are a large number of form controls, such as the backend of OA, the advantages of quickform will be shown. It’s out. Quickform has the characteristics of clear code and easy maintenance. It is very suitable for the development of large and medium-sized projects. What’s more convenient is that it can be easily used in smarty. ^_^ Without further ado, let’s take a look at the code. To understand the installation of PEAR, please refer to: http://hi.baidu.com/wanghaozi/blog/item/81cfb7003f973687e850cd3e.html.
Since the quickform used by the company has been improved by itself, the code will be slightly different from what you see online. It is inconvenient to explain the copyright involved here. I will briefly show the core code so that everyone can understand it. For those who are interested Friendsyou can read this HAOHAPPY article:http://www.phpe.net/articles/418.shtml
[php]
/*
*Author: Hui Boss
*Page: path .cfg.php
*Function: System path setting
*Copyright: copy as you like^_^
*/
$global['path']['conf'] = $global['path']['root'] . 'conf/';//Define the system configuration file path
$global['path']['lib'] = $global['path']['root'] . 'lib/';//Define the system library File path
?>
[/php]
[php]
/*
*Author: Hui Boss
*Page: smarty.cfg.php
*Function: smarty basic configuration
*Copyright: Just copy^_^
*/
//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 smarty configuration folder path
$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 smarty error reporting to disable
$global[' smarty']['debugging'] = false;
//Turn off caching
$global['smarty']['caching'] = false;
//$global['smarty']['cache_lifetime'] = 6000;
//Define the left and right boundary characters
$global['smarty']['left_delimiter'] = '<{';
$global['smarty']['right_delimiter'] = '}>';
?> ;
[/php]
[php]
/*
*Author: Hui Boss
*Page: common.cfg.php
*Function: Global configuration
*Copyright: copy as you like^_^
*/
$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 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']['debugging'];
$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]
/*
*Author: Hui Boss
*Page: index.php
*Function: UI
*Copyright: Whatever copy^_^
*/
require_once('common.inc.php');//Load global configuration
//Contains quickform class library
require($global['path']['lib'] . 'pear /HTML/QuickForm.php');
$form = new HTML_QuickForm('changepwdform');//Generate quickform instance, the parameter is the form name
/*
*Start adding form elements
*The parameters are: form element type, Name, (button label text), 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 and automatically generate JS
$form-> addRule('adminPwd','Password cannot be empty! ','required','','client');
$form->addRule('newPwd','The new password cannot be empty!','required','','client');
$form ->addRule('newPwd2','Please enter the new password again!','required','client');
$form->addRule(array('newPwd','newPwd2'),"Enter twice The passwords are inconsistent!",'compare','','client');
$form->;//Disable form submission
//Assign form data to an array
$tpl->assign('form_data',$form- >toArray());
//Display template
$tpl->display('index.tpl');
?>
[/php]
Template code:
Copy codeThe code is as follows :
<{if $form_data.javascrīpt}>
< ;{/if}>
;form <{$form_data.attributes}> >
Change administrator password | |||
tr> > Enter new password again ;td><{$form_data.newPwd2.html}> = "text/javascrīpt" src="response.js"> You may wonder here why the path is so complicated to define and use absolute What about the path? This is recently adapted to the needs of company projects, haha! In fact, this is helpful for deploying large projects. I believe that novices who have never been exposed to quickform or smarty will be confused by this post. Of course, I will only give a brief introduction here. I hope that everyone who is interested can continue to study in depth and finally see the effect: Look at the judgment and enter twice Check whether the passwords are the same: [php] $form->addRule(array('newPwd','newPwd2'),"The passwords entered twice are inconsistent!",'compare','','client' ); [/php] Does the code look concise and clear? Haha, it will be applied to applications combined with XAJAX next. I will continue to share my learning experience with everyone, hehe! The above introduces how to use smartprinter. Smarty+QUICKFORM is a small demonstration, including how to use smartprinter. I hope it will be helpful to friends who are interested in PHP tutorials. Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
![]() Hot AI Tools![]() Undresser.AI UndressAI-powered app for creating realistic nude photos ![]() AI Clothes RemoverOnline AI tool for removing clothes from photos. ![]() Undress AI ToolUndress images for free ![]() Clothoff.ioAI clothes remover ![]() Video Face SwapSwap faces in any video effortlessly with our completely free AI face swap tool! ![]() Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
3 weeks ago
By DDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months ago
By DDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks ago
By DDD
![]() Hot Tools![]() Notepad++7.3.1Easy-to-use and free code editor ![]() SublimeText3 Chinese versionChinese version, very easy to use ![]() Zend Studio 13.0.1Powerful PHP integrated development environment ![]() Dreamweaver CS6Visual web development tools ![]() SublimeText3 Mac versionGod-level code editing software (SublimeText3) ![]() Hot Topics
CakePHP Tutorial
![]() ![]() ![]() Alipay PHP... ![]() JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably, ![]() Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo ![]() Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS. ![]() The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection. ![]() How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo... ![]() How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode... ![]() Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead. ![]() |