基于 PHP 的表单验证助手?
从我使用 Ruby On Rails 开始,有几个不同的打包/项目可以以可扩展的方式管理验证和错误报告。
自学 Python Pylons 我刚刚了解了 HTMLFill,到目前为止,它似乎是表单验证常见任务的一个优雅的解决方案。
我知道这两个示例都是框架的功能,或者在 HTMLFill 的情况下,旨在成为框架的一部分......但我不记得在 cakephp、code igniter 甚至 Zend 框架中看到过任何远程的完善内容。 我是否遗漏了一些东西,或者是否值得尝试在 PHP5 中模仿 Python 的 HTMLFill?
免责声明: 我编写了基于 Ajax 的表单验证系统,该系统依赖于嵌入元数据,例如 class="data-required data-email" 等,但它们对我来说总是显得笨重。
我相信数据验证的胖模型哲学,通过上面的 HTMLFill 示例,我计划尽可能将通用 HTMLFill 方案打包到每个模型中。
链接: HTMLFill - http://www.formencode.org/htmlfill.html#introduction
From my time working with Ruby On rails, there is a couple different packaged/projects out there to manage both validation and error reporting in an extensible way.
Self-studying Python Pylons I just got introduced to HTMLFill which so far seems like an elegant solution to a common task of form validation.
I know both examples are features of Frameworks, or in the case of HTMLFill, intended to be part of a framework... still I don't remember seeing anything remotely as well polished in cakephp, code igniter, or even Zend framework. Am I missing something out there, or would it be worth while to attempt to imitate Python's HTMLFill in PHP5?
disclaimers:
I've written Ajax based form validation systems that rely on embedding metadata like class="data-required data-email" and like but they've always seemed clunky to me.
I believe in the fat model philosophy of data validation, with the HTMLFill example above, I plan on packing my models with common HTMLFill schemes to each model, as is possible.
Links:
HTMLFill - http://www.formencode.org/htmlfill.html#introduction
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Zebra Form 库非常好,可以自动生成 JavaScript 来进行客户端验证。
http://stefangabos.ro/php-libraries/zebra-form/
The Zebra Form library is pretty nice and automatically generates javascript to do client-side validation as well.
http://stefangabos.ro/php-libraries/zebra-form/
Zend Framework 有
Zend_Validate
类,它为您提供了一组基本的验证器,您还有Zend_Filter_Input
类用于数据过滤、验证和转义。我还使用 Propel ORM 验证框架 进行验证在模型级别。
您还可以在客户端级别强制执行验证,我推荐您 jQuery 验证插件< /a>,效果真的很好......
The Zend Framework has the
Zend_Validate
class, it provides you a basic set of validators, you have also theZend_Filter_Input
class for data filtering, validation and escaping.I've also used Propel ORM Validation Framework to do validation at the model level.
You can also enforce validation at the client side level, I recommend you the jQuery Validation plugin, it works really good...