Smarty and HTML

Source: Internet
Author: User
Tags quickform reset

Toss an afternoon, the Smarty and Html_quikform joined together the source code:

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 Joint Programming Experiment ') );
      $form->addelement (' text ', ' txtFirstName ', ' surname? ');
      $form->addelement (' text ', ' txtlastname ', ' respected name? ');
      $form->addelement (' text ', ' txtage ', ' age? ');
      $form->addelement (' text ', ' txttelephone ', ' phone? ');
      $form->addelement (' Reset ', ' btnclear ', ' Reset ');
      $form->addelement (' Submit ', ' btnsubmit ', ' submission ');
      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 is a good class library file for loading applications (that is, extended classes)
For example, you can include it in the index file.

Class Smarty_my extends Smarty {

function Smarty_my () {

Class constructor. These automatically get sets with each new instance.
Class constructors. Automatic configuration when creating an 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 ');
}

}

Template file 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 $-->
<link rel= "stylesheet" type= "Text/css" href= "Css/my.css"/>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

<body>

<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>
&LT;TD align= "Center" colspan= "4" >

</td>
</tr>
<!--Display the copyright-->
<tr>
&LT;TD style= "FONT-SIZE:11PX; Color:navy; Text-align:center "colspan=" 4 ">
©2005 Chen Experiment
</td>
</tr>
</table>

  Cascading model Table Files 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;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.