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

PHP
同台服务器使用缓存APC效率高于Memcached的演示代码
GBK的页面输出JSON格式的php函数
在字符串指定位置插入一段字符串的php代码
php 数组二分法查找函数代码
php htmlspecialchars加强版
支持数组的ADDSLASHES的php函数
判断是否为指定长度内字符串的php函数
php 读取文件乱码问题
PHP+ajax 无刷新删除数据
php microtime获取浮点的时间戳
php 魔术函数使用说明
php 高效率写法 推荐
PHP 学习路线与时间表
php中理解print EOT分界符和echo EOT的用法区别小结
Search File Contents PHP 搜索目录文本内容的代码
收藏的PHP常用函数 推荐收藏保存
PHP 伪静态隐藏传递参数名的四种方法
PHP实现域名whois查询的代码(数据源万网、新网)
php 用checkbox一次性删除多条记录的方法
php str_pad() 将字符串填充成指定长度的字符串

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


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