当前位置: 首页 > 图文教程 > 网络编程 > PHP > 实例操作:PEAR的HTML_QuickForm7应用

PHP
PHP 柱状图实现代码
PHP 用数组降低程序的时间复杂度
PHP 读取文件内容代码(txt,js等)
Php 构造函数construct的前下划线是双的_
PHP 采集程序中常用的函数
一个比较简单的PHP 分页分组类
php下图片文字混合水印与缩略图实现代码
php5 图片验证码实现代码
phpmyadmin导入(import)文件限制的解决办法
php smarty模版引擎中变量操作符及使用方法
Php Mssql操作简单封装支持存储过程
php实现的仿阿里巴巴实现同类产品翻页
php入门教程 精简版
将文件夹压缩成zip文件的php代码
PHP开发过程中常用函数收藏
php csv操作类代码
php遍历目录viewDir函数
PHP 基本语法格式
php生成xml简单实例代码
PHP下编码转换函数mb_convert_encoding与iconv的使用说明

PHP 中的 实例操作:PEAR的HTML_QuickForm7应用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 100 ::
收藏到网摘: n/a


    【PHPChina讯】程序员们往往被告之不要去重复地编写程序, 而且最好的程序员在写他们自己的程序的时候都会借鉴别人的。PHP,作为一个基本的Web语言,常见于form的显示,处理和验证(确认)。然而,有一个强大的PEAR包需要更多的关注:它就是HTML_QuickForm,它促使图的提交和form的显示,而且更有用的是,客户端和服务器端都能够得到验证,即快又简单。这篇文章会让你了解PEAR包的基本知识。他假定你已有HTML表格基础,并且有基本的PHP技能。

    安装HTML_QuickForm

    安装PEAR包只需要两个条件:PHP4.2版本以上,并且有HTML_Common包。现在为止HTML_QuickForm 3.2.7是最新的版本,它需要对应的HTML_Common 1.2.1。有人在为PHP5写这两个包(以HTML_QuickForm2和 HTML_Common2的形式),但是还没有发布。

    你可以通过以下pear list检查PEAR是否已经安装:
pear list
Installed packages:
===================
Package        Version State
Archive_Tar     1.1     stable
Console_Getopt 1.2     stable
DB               1.6.2   stable
Date            1.4.6   stable
HTTP            1.2.2   stable
Image_Canvas   0.3.0   alpha
Image_Color    1.0.2   stable
Image_Graph    0.7.2   alpha
Mail            1.1.3   stable
Net_SMTP       1.2.6   stable
Net_Socket     1.0.1   stable
PEAR           1.3.2   stable
Validate       0.6.3   beta
XML_Parser     1.0.1   stable
XML_RPC        1.1.0   stable

    从以上可以知道,你的机器即没有HTML_QuickForm 也没有 HTML_Common,所以它们需要被安装:
pear install HTML_Common
downloading HTML_Common-1.2.3.tgz ...
Starting to download HTML_Common-1.2.3.tgz (4,746 bytes)
.....done: 4,746 bytes
install ok: HTML_Common 1.2.3

pear install HTML_QuickForm
downloading HTML_QuickForm-3.2.7.tgz ...
Starting to download HTML_QuickForm-3.2.7.tgz (102,475 bytes)
........................done: 102,475 bytes
install ok: HTML_QuickForm 3.2.7
 
    显示form

    使用代码去显示一个表单很简单,让我们以一个例子开始:
<?php
 require_once "HTML/QuickForm.php"; // tell PHP to include the QuickForm package

  $form = new HTML_QuickForm('register', 'post');  // instantiate the object
  $form->addElement('text', 'firstName', 'Enter first name'); // add a text element
  $form->addElement('password','password', 'Enter your password'); // add a password element
  $form->addElement('textarea','ta','Description'); // add a textarea element
  $form->addElement('submit','sb','Submit form'); // add a submit button element

  $form->display();
?>


    很明了这小段代码的意思:包的引入,对象的示例,然后加入元素(称作FirstName的:在它之后输入你的first name;password:在它之后输入你的password。)下面是HTML代码的样子:
<form action="/phpbuilder/html_quickform11.php" method="post" name="register" id="register">
<div>
<table border="0">

 <tr>
  <td align="right" valign="top"><b>Enter first name</b></td>
  <td valign="top" align="left"> <input name="firstNa"