Smarty+QUICKFORM小小演示
框架(架构)  /  管理员 发布于 5年前   121
由于公司用的quickform是自己改进过的,因此代码和大家网上看到的会有些差别,涉及版权在这里就不便说明,简要展示下核心代码,大家就当了解下吧,有兴趣的朋友可以看看这篇HAOHAPPY的文章:http://www.phpe.net/articles/418.shtml
[php]
/*
*作者:辉老大
*页面:path.cfg.php
*功能:系统路径设置
*版权所有:随便copy^_^
*/
$global['path']['conf'] = $global['path']['root'] . 'conf/';//定义系统配置文件路径
$global['path']['lib'] = $global['path']['root'] . 'lib/';//定义系统库文件路径
?>
[/php]
[php]
/*
*作者:辉老大
*页面:smarty.cfg.php
*功能:smarty基本配置
*版权所有:随便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;
//设置smarty报错禁用
$global['smarty']['debugging'] = false;
//关闭缓存
$global['smarty']['caching'] = false;
//$global['smarty']['cache_lifetime'] = 6000;
//定义左右边界符
$global['smarty']['left_delimiter'] = '<{';
$global['smarty']['right_delimiter'] = '}>';
/*
*作者:辉老大
*页面:common.cfg.php
*功能:全局配置
*版权所有:随便copy^_^
*/
$global['path']['root'] = dirname(__FILE__) . '/';//设置根目录
require($global['path']['conf'] . 'conf/path.cfg.php');
require($global['path']['conf'] . 'smarty.cfg.php');
//包含smarty类库
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库文件
?>
[/php]
[php]
/*
*作者:辉老大
*页面:index.php
*功能:UI
*版权所有:随便copy^_^
*/
require_once('common.inc.php');//载入全局配置
//包含quickform类库
require($global['path']['lib'] . 'pear/HTML/QuickForm.php');
$form = new HTML_QuickForm('changepwdform');//生成quickform实例,参数为表单名
/*
*开始添加表单元素
*参数依次为:表单元素类型,名称,(按钮标签文字),样式
*/
$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"');
//增加验证规则,自动生成JS
$form->addRule('adminPwd','密码不能为空!','required','','client');
$form->addRule('newPwd','新密码不能为空!','required','','client');
$form->addRule('newPwd2','请再次输入新密码!','required','client');
$form->addRule(array('newPwd','newPwd2'),"两次输入的密码不一致!",'compare','','client');
$form->;//禁止提交表单
//分配表单数据到数组中
$tpl->assign('form_data',$form->toArray());
//显示模板
$tpl->display('index.tpl');
?>
[/php]
模板代码:
看判断两次输入密码是否一样就这一句:
[php]
$form->addRule(array('newPwd','newPwd2'),"两次输入的密码不一致!",'compare','','client');
[/php]
代码看起来是不是简洁清楚啊,呵呵,接下来还会应用到再结合XAJAX的应用,我会继续和大家分享学习心得,嘿嘿!
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号