Smarty+QUICKFORM small demonstration_PHP tutorial
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, For example, in the backend of OA, the advantages of quickform are shown. Using quickform has the characteristics of clear code and easy maintenance. It is very suitable for the development of large and medium-sized projects. What is more convenient is that it can be easily used in smarty. ^_^ Stop talking nonsense. , let’s take a look at the code, but it’s best for everyone to understand the installation of PEAR before, 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. Interested friends 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: Whatever copy^_^
*/
$global['path']['conf'] = $global['path']['root'] . 'conf/';//Define the system Configuration file path
$global['path']['lib'] = $global['path']['root'] . 'lib/';//Define system library file path
?>
[/php]
[php]
/*
*Author: Hui Boss
*Page: smarty.cfg.php
*Function: smarty basic configuration
*Copyright: copy as you like^_^
*/
//Define template path
$global['smarty']['template_dir '] = $global['path']['root'] . 'lib/smarty/templates';
//Define template compilation directory
$global['smarty']['compile_dir'] = $ global['path']['root'] . 'lib/smarty/templates_c';
//Define smarty configuration folder path
$global['smarty']['config_dir'] = $global[ 'path']['conf']. 'lib/smarty/configs'; 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 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: copy as you like^_^
*/
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 quickform instance, the parameters are 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' ),"The passwords entered twice 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:
<{if $form_data.javascrīpt}>
<{$form_data.javascrīpt} >
<{/if}>
< ;/BODY>
You may wonder here why the path definition is so complicated and absolute paths are used? 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 briefly introduce it here. I hope that if you are interested, you can continue to study it in depth and finally see the effect:
[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 also be applied to applications combined with XAJAX. I will continue to share it with you. Learning experience, hehe!
http://www.bkjia.com/PHPjc/317876.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What does WeChat Do Not Disturb mode mean? Nowadays, with the popularity of smartphones and the rapid development of mobile Internet, social media platforms have become an indispensable part of people's daily lives. WeChat is one of the most popular social media platforms in China, and almost everyone has a WeChat account. We can communicate with friends, family, and colleagues in real time through WeChat, share moments in our lives, and understand each other’s current situation. However, in this era, we are also inevitably faced with the problems of information overload and privacy leakage, especially for those who need to focus or

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Blue Star Travel Ballad has been on the game hot list after the recent release of a promotional video. Many players are very curious about which company Blue Star Travel Ballad is made from. In fact, it is a new game from Shanghai 2D manufacturer Manjiu. The editor will explain it to you below. Here is the introduction of Blue Star Yuanluyao Game Company, come and take a look together. Which company does Blue Star Travel Yao come from? Answer: It was launched by Manjiu Network. 1. First of all, Blue Star Travel Yao is a game launched by Manju’s Big World RPG. A promotional video was released on March 20. 2. This product will get its version number in October 2023. The game's trademark and operating unit are both registered under the name of a company called. The latter was established in February 2023, and its official website shows that its headquarters is in Singapore. 3. The 11-minute promotional video released this time revealed this

Android development is a busy and exciting job, and choosing a suitable Linux distribution for development is particularly important. Among the many Linux distributions, which one is most suitable for Android development? This article will explore this issue from several aspects and give specific code examples. First, let’s take a look at several currently popular Linux distributions: Ubuntu, Fedora, Debian, CentOS, etc. They all have their own advantages and characteristics.

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces
