PHP和jQuery表单创建和验证库可用? [英] A PHP and jQuery form creation and validation library available?

查看:121
本文介绍了PHP和jQuery表单创建和验证库可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一个经过良好测试,最好是成熟的库,用于在PHP中创建客户端的表单(这是jQuery的入口)和服务器端验证?



理想情况下,表单可以从PHP类生成,或者编写为纯HTML并解析为ala Agavi 。然后,库自动创建正确的jQuery钩子,以便包含的jQuery客户端验证可以运行。



我经常做的一项工作是好的旧联系表格,我希望将这项工作标准化,以便我可以每次都拿出相同的最佳实践代码。考虑到这一点,PHP类生成的HTML应该足够好,以便可以在需要时添加额外的CSS钩子等。



感激地收到了任何建议。






更新



我一直在梳理和回顾已经发现并且其他人在下面提出了建议,目前我会按照以下顺序对项目进行排序,以便从我对所有人进行的少量测试和研究中获得质量。


  1. ValidForm Builder

  2. jFormer

  3. HTML_QuickForm2 (如果你能得到客户端验证的工作,那么这应该比jFormer跳得更高!) php-form-b​​uilder-class

  4. 使用Symfony!(整个MVC框架的表单呈现和验证是过度杀伤)

我仍然不相信任何选择是诚实的我仍然想知道为什么从事这些项目的人不会从一些经过严格测试的组件开始。例如,我会想到一个组合:





为您提供良好的稳定基础,并在测试组件之上生成一个不错的库。

另外,如果您对解析HTML的库感兴趣,而不是从PHP类生成HTML,我发现一个名为 Minacl 。像原始问题中提到的 Agavi 选项。

解决方案

您可以使用 ValidForm Builder 。它与您的需求完美匹配:
使用它,您可以使用PHP中的验证规则定义Forms,并通过jQuery和客户端验证生成表单。



功能列表(取自他们的网站):


  • API生成符合XHTML Strict 1.0的代码。

  • 在客户端进行字段验证,以最大限度地减少通信开销。

  • 在服务器端进行字段验证,以强制实施验证规则,并防止通过SQL注入对形式
    进行回火。 >
  • 客户端验证以内联方式显示,以提高用户满意度。没有更多恼人的弹出窗口不能真正告诉你什么。

  • 轻松创建复杂的表单结构。

  • 使用流行的jQuery Javascript库。
  • 使用CSS完全自定义。

  • 以HTML和纯文本自动为表单邮件程序创建字段汇总。

  • 它是开源的,因此完全免费(这里是GitHub repo )!


Original Question

Is there a well tested and preferably mature library out there for creating forms in PHP with both client side (this is where the jQuery comes in) and server side validation?

Ideally the form would either be generated from PHP classes or written as plain HTML and parsed ala Agavi. The correct jQuery hooks would then automatically be created by the library so that the included jQuery client side validation can run.

One of the jobs I do regularly is some variation on the good old contact form and I would like to standardise this work so that I can trot out the same best practice code each time. With this in mind the HTML generated by the PHP classes should be good enough so that extra CSS hooks can be added where needed etc.

Any suggestions gratefully received.


Update

I have been combing through and reviewing the options that I have found and that others have suggested below and at the moment I would rank the projects in the following order for quality from the small amount of testing and research I have done on all of them.

  1. ValidForm Builder
  2. jFormer
  3. HTML_QuickForm2 (if you can get the client side validation working then this should jump higher than jFormer!)
  4. php-form-builder-class
  5. Use Symfony! (a whole MVC framework for form rendering and validation is overkill)

I am still unconvinced by any of the options to be honest and I am left wondering why people who embark on these projects do not start with some solid and well tested components. For example I would have thought a combination of:

Would give you a good stable base to work from and produce a nice library on top of tested components.

Also if you are interested in a library that parses your HTML rather than generating the HTML from a PHP class I have found a project called Minacl. Like the Agavi option I mentioned in the original question.

解决方案

You can use ValidForm Builder. It matches perfect to your requirements: With it you can define Forms with validation rules in PHP, and it generates the Forms with jQuery and client side validation.

Feature List (taken from their site):

  • The API generates XHTML Strict 1.0 compliant code.
  • Field validation on the client side to minimize traffic overhead.
  • Field validation on the server side to enforce validation rules and prevent tempering with the form through SQL injection.
  • Client side validation displays inline to improve user satisfaction. No more annoying popups that don't really tell you anything.
  • Easy creation of complex form structures.
  • Uses the popular jQuery Javascript library for DOM manipulation.
  • Completely customizable using CSS.
  • Automatic creation of field summaries for form mailers in both HTML and plain text.
  • It's open source and therefore completely free (here's the GitHub repo)!

这篇关于PHP和jQuery表单创建和验证库可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆