使用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 ,内容如下: (由于图片大小的限制,所有的注释都被删除了) 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规则摘录如下:
|