您的位置:首页 > 理论基础 > 计算机网络

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

2016-08-28 11:43 483 查看
使用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规则摘录如下: '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

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

注: http://zend.cn   zend.cn 是测试时使用的本地(localhost)虚拟主机 可以看到,使用HTML_QuickForm,不仅将表单的生成和验证(服务器端、客户端)封装到一起。而且由于将表单作为一个对象,提高了它的复用能力。例如:本文中,添加记录和编辑记录使用了同一个表单对象(编辑时对修改了表单对象)。 备注: 引导文件 /html/index.php 如下


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: