|
由于公司用的quickform是自己改進(jìn)過(guò)的,因此代碼和大家網(wǎng)上看到的會(huì)有些差別,涉及版權(quán)在這里就不便說(shuō)明,簡(jiǎn)要展示下核心代碼,大家就當(dāng)了解下吧,有興趣的朋友可以看看這篇HAOHAPPY的文章:http://www.phpe.NET/articles/418.shtml
[php]
<?php
/*
*作者:輝老大
*頁(yè)面:path.cfg.php
*功能:系統(tǒng)路徑設(shè)置
*版權(quán)所有:隨便copy^_^
*/
$global['path']['conf'] = $global['path']['root'] . 'conf/';//定義系統(tǒng)配置文件路徑
$global['path']['lib'] = $global['path']['root'] . 'lib/';//定義系統(tǒng)庫(kù)文件路徑
?>
[/php]
[php]
<?php
/*
*作者:輝老大
*頁(yè)面:smarty.cfg.php
*功能:smarty基本配置
*版權(quán)所有:隨便copy^_^
*/
//定義模板路徑
$global['smarty']['template_dir'] = $global['path']['root'] . 'lib/smarty/templates';
//定義模板編譯目錄
$global['smarty']['compile_dir'] = $global['path']['root'] . 'lib/smarty/templates_c';
//定義smarty配置文件夾路徑
$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;
//設(shè)置smarty報(bào)錯(cuò)禁用
$global['smarty']['debugging'] = false;
//關(guān)閉緩存
$global['smarty']['caching'] = false;
//$global['smarty']['cache_lifetime'] = 6000;
//定義左右邊界符
$global['smarty']['left_delimiter'] = '<{';
$global['smarty']['right_delimiter'] = '}>';
?>
[/php]
[php]
<?php
/*
*作者:輝老大
*頁(yè)面:common.cfg.php
*功能:全局配置
*版權(quán)所有:隨便copy^_^
*/
$global['path']['root'] = dirname(__FILE__) . '/';//設(shè)置根目錄
require($global['path']['conf'] . 'conf/path.cfg.php');
require($global['path']['conf'] . 'smarty.cfg.php');
//包含smarty類(lèi)庫(kù)
require($global['path']['lib'] . 'smarty/libs/Smarty.class.php');
//smarty配置
$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/');//載入pear庫(kù)文件
?>
[/php]
[php]
<?php
/*
*作者:輝老大
*頁(yè)面:index.php
*功能:UI
*版權(quán)所有:隨便copy^_^
*/
require_once('common.inc.php');//載入全局配置
//包含quickform類(lèi)庫(kù)
require($global['path']['lib'] . 'pear/HTML/QuickForm.php');
$form = new HTML_QuickForm('changepwdform');//生成quickform實(shí)例,參數(shù)為表單名
/*
*開(kāi)始添加表單元素
*參數(shù)依次為:表單元素類(lèi)型,名稱(chēng),(按鈕標(biāo)簽文字),樣式
*/
$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','修改密碼','style="width:100px"');
//增加驗(yàn)證規(guī)則,自動(dòng)生成JS
$form->addRule('adminPwd','密碼不能為空!','required','','client');
$form->addRule('newPwd','新密碼不能為空!','required','','client');
$form->addRule('newPwd2','請(qǐng)?jiān)俅屋斎胄旅艽a!','required','client');
$form->addRule(array('newPwd','newPwd2'),"兩次輸入的密碼不一致!",'compare','','client');
$form->;//禁止提交表單
//分配表單數(shù)據(jù)到數(shù)組中
$tpl->assign('form_data',$form->toArray());
//顯示模板
$tpl->display('index.tpl');
?>
[/php]
模板代碼:
復(fù)制代碼 代碼如下:
<HTML>
<HEAD>
<TITLE>quickform+smarty</TITLE>
<{if $form_data.Javascrīpt}>
<{$form_data.Javascrī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">修改管理員密碼</div></tr>
<tr>
<tr>
<td width="47%"><div align="center">現(xiàn)有管理員密碼
</div></td>
<td width="53%"><{$form_data.adminPwd.html}></td>
</tr>
<tr>
<td><div align="center">新密碼
</div></td>
<td><{$form_data.newPwd.html}></td>
</tr>
<tr>
<td><div align="center">再次輸入新密碼
</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īpt type="text/Javascrīpt" src="response.js"></scrīpt>
</BODY>
</HTML>
這里大家也許覺(jué)得奇怪,為什么路徑要定義這么復(fù)雜,而且使用絕對(duì)路徑呢?這個(gè)是最近適應(yīng)公司項(xiàng)目的需要,呵呵!其實(shí)這樣有利于部署大的項(xiàng)目。這個(gè)帖子相信沒(méi)接觸過(guò)quickform或smarty的新手一定看的一頭霧水,當(dāng)然,我在這也只是簡(jiǎn)單介紹下,希望大家有興趣的可以繼續(xù)深入研究,最后看看效果:
看判斷兩次輸入密碼是否一樣就這一句:
[php]
$form->addRule(array('newPwd','newPwd2'),"兩次輸入的密碼不一致!",'compare','','client');
[/php]
代碼看起來(lái)是不是簡(jiǎn)潔清楚啊,呵呵,接下來(lái)還會(huì)應(yīng)用到再結(jié)合XAJAX的應(yīng)用,我會(huì)繼續(xù)和大家分享學(xué)習(xí)心得,嘿嘿!
php技術(shù):Smarty+QUICKFORM小小演示,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。