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

PHP
用PHP实现ODBC数据分页显示一例
用DBSQL类加快开发MySQL数据库程序的速度
多php服务器实现多session并发运行
多核编程中的负载平衡难题
将Oracle内置的安全特性用于php
在PHP中使用ASP.NET AJAX
php中计算时间差的几种方法
PHP 5.0对象模型深度探索之类的静态成员
让PHP管理小型的邮件列表
MagickWand for PHP linux INSTALL 安装
PHP中数组元素升序、降序及重新排序的函数
PHP后门的隐藏技巧测试报告
配置Apache 1.3或者Apache 2.0服务器的5个技巧
用Suhosin加强PHP脚本语言安全性
PHP动态网页编程常用技巧四则
解答:如何使用PHP开发高效的WEB系统
PHP实现上传文件生成小图加文字的实例
PHP实现定时生成HTML网站首页
教你用PHP写MySQL数据库的用户认证系统
加速动态网站 MySQL索引分析和优化

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 38 ::
收藏到网摘: 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"