首页 > 开发 > PHP > 正文

smarty和html_QuikForm联合编程

2024-05-04 23:04:32
字体:
来源:转载
供稿:网友

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

test.php

<?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

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

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

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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
  <!--  $id: smarty-guide.tpl,v 1.1 2005/03/03 19:26:54 kae exp $ -->
 <head>
<link rel="stylesheet" type="text/css" href="css/my.css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
 
  </head>

  <body>
  <h2>
   
  </h2>
  <form >
    <!-- display the fields -->
    <table>
      <tr>
        <th></th>
        <td></td>
        <th></th>
        <td></td>
      </tr>
      <tr>
        <th></th>
        <td></td>
        <th></th>
        <td></td>
      </tr>
      <!-- display the buttons -->
      <tr>
        <td align="center" colspan="4">
          &nbsp;
        </td>
      </tr>
      <!-- display the copyright -->
      <tr>
        <td colspan="4">
          &copy;2005 陈刚 实验
        </td>
      </tr>
    </table>

  层叠式样表文件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;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表