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

PHP
PHP memcache扩展的三种安装方法
PHP 判断常量,变量和函数是否存在
PHP session有效期问题
PHP 读取文件的正确方法
apache2.2.4+mysql5.0.77+php5.2.8安装精简
PHP 字符串编码截取函数(兼容utf-8和gb2312)
PHP 错误之引号中使用变量
php 购物车的例子
PHP 身份证号验证函数
php结合飞信 免费天气预报短信
PHP SQLite类
PHP 在线翻译函数代码
PHPMyAdmin 快速配置方法
PHP 编写的 25个游戏脚本
php 购物车实例(申精)
PHP获取当前文件所在目录 getcwd()函数
DISCUZ 论坛管理员密码忘记的解决方法
PHP 采集心得技巧
抓取YAHOO股票报价的类
PHP 模拟登陆MSN并获得用户信息

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


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