首页 > php教程 > php手册 > 正文

smarty和html_QuikForm联合编程

php中文网
发布: 2016-06-21 08:59:17
原创
1517人浏览过

  折腾一个下午,把smarty和html_QuikForm联结到一起了源码:

test.php

      require_once "HTML/QuickForm.php";
      require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
      require_once 'link/myload.php';

      $form = new HTML_QuickForm('frmTest', 'get');
      $form->addElement('header', 'hdrTesting', 'Smarty&HTML/QuickForm联合编程实验');
      $form->addElement('text', 'txtFirstName', '贵姓?');
      $form->addElement('text', 'txtLastName', '尊名?');
      $form->addElement('text', 'txtAge', '年龄?');
      $form->addElement('text', 'txtTelephone', '电话?');
      $form->addElement('reset', 'btnClear', '复位');
      $form->addElement('submit', 'btnSubmit', '提交');
      if ($form->validate()) {
          # If the form validates then freeze the data
          $form->freeze();
      }

      // Create the template object
      $tpl =$smarty=& new Smarty_my;
    
            $tpl->compile_check = true;
      // Create the renderer object   
      $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);

      // build the HTML for the form
      $form->accept($renderer);

      // assign array with form data
      $tpl->assign('form_data', $renderer->toArray());

      // parse and display the template
      $tpl->display('my.tpl');

  ?>

mylink.php

// load Smarty library
define('myclude',/usr/share/php/smarty');
require(myinclude.'/libs/Smarty.class.php');

//setup.php是一个很好的加载应用程序的类库文件(就是扩展类)
//例如你可以在index文件里包含它

豆包AI编程
豆包AI编程

豆包推出的AI编程助手

豆包AI编程 483
查看详情 豆包AI编程

class Smarty_my extends Smarty {

   function Smarty_my() {
  
           // Class Constructor. These automatically get set with each new instance.
//类构造函数.创建实例的时候自动配置
        $this->Smarty();

        $this->template_dir = '/var/www/apache2-default/smarty/xsgl/templates/';
        $this->compile_dir = '/var/www/apache2-default/smarty/xsgl/templates_c/';
        $this->config_dir = '/var/www/apache2-default/smarty/xsgl/configs/';
        $this->cache_dir = '/var/www/apache2-default/smarty/xsgl/cache/';
       
        $this->caching = true;
        $this->assign('app_name','xsgl');
   }

}

模板文件my.tpl


 
 




 
 

 


 


   
 


 

   
   
     
       
       
       
       
     
     
       
       
       
       
     
     
     
       
     
     
     
       
     
   

           
       

          ©2005 陈刚 实验
       

  层叠式样表文件my.css

body {
    background-color: #10F2E7;
}

 table  
n {
    font-size: small;
    font-family: arial, helvetica, sans-serif;
}
table {
    overflow: scroll;
    margin: 0.1px;
    font-weight: lighter;
    font-family: arial, helvetica, sans-serif;
}



最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号