使用Pear QuickForm创建和验证表单2008-02-13 17:37这是Zend上的一篇文章 http://devzone.zend.com/article/2699-Generating-and-Validating-Web-Forms-Wit

使用Pear QuickForm创建和验证表单

2008-02-13 17:37

这是Zend上的一篇文章 http://devzone.zend.com/article/2699-Generating-and-Validating-Web-Forms-With-PEAR-HTML_QuickForm ,阅读后笔记如下(不算翻译,但应该可以代替原文)

本文不准备系统的介绍Pear HTML_QuickForm的基本用法,对于这个,您可以访问 Haohappy 的博客。

准备:

PHP5 (本人使用 PHP5.30 dev)

Pear

HTML Common

HTML_QuickForm 3.20

Zend Framework 1.50 Preview

目录结构如下:

├─application

│ ├─controllers

│ ├─models

│ └─views

│      ├─filters

│      ├─helpers

│      └─scripts

│          ├─index

│          └─quick

├─html

│ ├─css

│ └─image

└─Lib

    ├─Pear

    │ └─HTML

    │      └─QuickForm

    │          ├─Renderer

    │          └─Rule

    └─Zend

/html/ 为 document root

创建 QuickController.php ,内容如下:

使用Pear QuickForm创建和验证表单2008-02-13 17:37这是Zend上的一篇文章 http://devzone.zend.com/article/2699-Generating-and-Validating-Web-Forms-With-PEAR-HTML_QuickForm ,阅读后笔记如下(不算翻译,但应该可以代替原文) - ufo - 飞颖站点

(由于图片大小的限制,所有的注释都被删除了)

1、 _getForm()    创建表单对象

2、 checkdate($value)     检查表单日期输入的callback。 注意: callback 必须是 public 的

3、 _showform($form)     将表单对象输出到客户端

4、 _dopost()              当前的Controller中处理一切POST请求的方法

5、 addAction()        暴露对外的一个Action,处理添加新内容相关的请求

6、 editAction()      暴露对外的,显示修改内容表单的Action

7、 editpostAction   暴露对外,接受修改后内容的Action

8、 _getOldData()    用于模拟修改数据时获取原有数据的Mock

Rule规则摘录如下:

  • 'required' - the input value is mandatory;
  • 'maxlength' - the input value must not contain more than the specified number of characters;
  • 'minlength' - the input value must not contain less than the specified number of characters;
  • 'rangelength' - the length of the input value must fall within the specified range;
  • 'email' - the input value must correspond to the general form of an email address;
  • 'regex' - the input value must correspond to the specified regular expression;
  • 'lettersonly' - the input value can only contain alphabetic characters;
  • 'alphanumeric' - the input value can only contain alphanumeric characters;
  • 'numeric' - the input value can only contain numbers;
  • 'nopunctuation' - the input value cannot contain punctuation characters;
  • 'nonzero' - the input value cannot be zero;
  • 'callback' - the input value is to be passed to a named external function for validation;
  • 'compare' - the input value must be equal to another input element;

    显示表单的视图文件 /views/scripts/quick/form-window.phtml

    使用Pear QuickForm创建和验证表单2008-02-13 17:37这是Zend上的一篇文章 http://devzone.zend.com/article/2699-Generating-and-Validating-Web-Forms-With-PEAR-HTML_QuickForm ,阅读后笔记如下(不算翻译,但应该可以代替原文) - ufo - 飞颖站点

    最后,显示界面如下 (http://zend.cn/quick/edit/

    使用Pear QuickForm创建和验证表单2008-02-13 17:37这是Zend上的一篇文章 http://devzone.zend.com/article/2699-Generating-and-Validating-Web-Forms-With-PEAR-HTML_QuickForm ,阅读后笔记如下(不算翻译,但应该可以代替原文) - ufo - 飞颖站点

    注: http://zend.cn   zend.cn 是测试时使用的本地(localhost)虚拟主机

    可以看到,使用HTML_QuickForm,不仅将表单的生成和验证(服务器端、客户端)封装到一起。而且由于将表单作为一个对象,提高了它的复用能力。例如:本文中,添加记录和编辑记录使用了同一个表单对象(编辑时对修改了表单对象)。

    备注:

    引导文件 /html/index.php 如下

    使用Pear QuickForm创建和验证表单2008-02-13 17:37这是Zend上的一篇文章 http://devzone.zend.com/article/2699-Generating-and-Validating-Web-Forms-With-PEAR-HTML_QuickForm ,阅读后笔记如下(不算翻译,但应该可以代替原文) - ufo - 飞颖站点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值