使用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 如下 |
相关文章推荐
- yii 使用cactiveform 创建表单时候遇到的一些验证问题和使用ajax_form时重置验证规则的解决办法
- web创建form表单验证码
- 实现使用HTTP协议发送multipart/form-data类型的HTTP表单
- 使用 gSOAP 通过 HTTP 和 HTTPS 调用由 WSAD 创建的 J2EE Web 服务
- 如何使用 Forms 身份验证创建 GenericPrincipal 对象
- c# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用
- asp.net Forms表单验证 使用经验及验证流程分析
- [转自http://jhtchina.cnblogs.com/]Dev里面DataGid控件使用方法之一
- 网页编程之验证码识别技术 http://www.meiyisi.com/article.asp?id=1751
- 实现使用HTTP协议发送multipart/form-data类型的HTTP表单
- 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
- FLex Builder环境 使用 说明 BLOG http://www.akooc.com/article.asp?id=141
- 使用 gSOAP 通过 HTTP 和 HTTPS 调用由 WSAD 创建的 J2EE Web 服务
- javascript attachEvent和addEventListener 使用方法--http://www.diybl.com/course/1_web/javascript/jsjs/20071226/94592.html
- 如何使用 Forms 身份验证创建 GenericPrincipal 对象
- 使用AbstractWizardFormController提交复杂表单的验证解决方案
- 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
- FCKeditor 2.3 在ASP.NET中的设置和使用http://blog.licns.com/blog/article.asp?id=173
- HttpWebRequest使用有身份验证的代理
- 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie