Ajax validation support would also be a plus.
Ajax验证支持也是一个优势。
I want to define my form in PHP, call render(); and have all the HTML and user friendly javascript validation done for me based on what rules I add in PHP.
我想在PHP中定义我的表单,调用render();并根据我在PHP中添加的规则为我完成所有HTML和用户友好的javascript验证。
The best library I could find is http://www.jformer.com/ but it's a mess, it uses iframes with a src of empty.html (for who knows why), and the way you process forms is awkward too.
我能找到的最好的图书馆是http://www.jformer.com/,但它很乱,它使用iframe与src的empty.html(谁知道为什么),你处理表单的方式也很尴尬。
Is there anything else like this?
还有其他类似的东西吗?
2 个解决方案
#1
1
Zend_Form from Zend Framework does this. Primarily it does server side validation of the forms, but you could extend it do basic client side validation as well. Using it in conjunction with Zend_Dojo may give you some additional client side capabilities as well.
Zend Framework的Zend_Form就是这样做的。它主要是对表单进行服务器端验证,但您也可以扩展它以进行基本的客户端验证。将它与Zend_Dojo结合使用可以为您提供一些额外的客户端功能。
You can also handle the forms via ajax or HTTP GET/POST. Also, you don't need to use the entire Zend Framework to use Zend_Form, it would be possible to get it working as a standalone component.
您还可以通过ajax或HTTP GET / POST处理表单。此外,您不需要使用整个Zend Framework来使用Zend_Form,因此可以将其作为独立组件运行。
#2
0
Yii2 does this pretty well.
Yii2做得很好。
http://www.yiiframework.com/doc-2.0/guide-input-validation.html#client-side-validation
But i'm not sure if you can use this without using the full yii2 framework.
但我不确定你是否可以在不使用完整的yii2框架的情况下使用它。
The way it works is that you put validation rules in your yii2 models (activerecord-style).
它的工作方式是将验证规则放在yii2模型中(activerecord-style)。
Core built in validators support both client and server side validation. If you create custom validator rules (always happens unless you do very basic forms). Then you can pick if you will do server side only or implement client side as well.
内置验证器的核心支持客户端和服务器端验证。如果您创建自定义验证器规则(除非您执行非常基本的表单,否则总是会发生)。然后,您可以选择是仅执行服务器端还是实现客户端。
You use a yii2 widget called activeform. You pass your model to activeform. It renders the form for you (it's flexible, and you don't have to render everything with it if you dont want to, it includes the javascript required to handle the validation etc.
您使用名为activeform的yii2小部件。您将模型传递给activeform。它为您呈现表单(它是灵活的,如果您不想,它不必使用它呈现所有内容,它包含处理验证所需的javascript等。
you define a yii2 controller and action to handle the server side form submission and pass the POST-data to your model. then you call the models validate() method to validate server side .. and if needed you can render the form again by passing the invalid $model to the activeform and it will display errors.
您定义了一个yii2控制器和操作来处理服务器端表单提交并将POST数据传递给您的模型。然后你调用模型validate()方法来验证服务器端..如果需要你可以通过将无效的$ model传递给activeform来再次渲染表单,它将显示错误。
It also has ajax-capabilities, not sure exactly how it works, but it still does client and server side validation.
它还具有ajax功能,不确定它是如何工作的,但它仍然进行客户端和服务器端验证。
Let me know if you try this and successfully extract only what is needed from yii2 to do this. I would like to use this part of yii2 without having the full yii2 framework.
如果您尝试这个并成功提取yii2所需的内容,请告诉我。我想在没有完整的yii2框架的情况下使用yii2的这一部分。
#1
1
Zend_Form from Zend Framework does this. Primarily it does server side validation of the forms, but you could extend it do basic client side validation as well. Using it in conjunction with Zend_Dojo may give you some additional client side capabilities as well.
Zend Framework的Zend_Form就是这样做的。它主要是对表单进行服务器端验证,但您也可以扩展它以进行基本的客户端验证。将它与Zend_Dojo结合使用可以为您提供一些额外的客户端功能。
You can also handle the forms via ajax or HTTP GET/POST. Also, you don't need to use the entire Zend Framework to use Zend_Form, it would be possible to get it working as a standalone component.
您还可以通过ajax或HTTP GET / POST处理表单。此外,您不需要使用整个Zend Framework来使用Zend_Form,因此可以将其作为独立组件运行。
#2
0
Yii2 does this pretty well.
Yii2做得很好。
http://www.yiiframework.com/doc-2.0/guide-input-validation.html#client-side-validation
But i'm not sure if you can use this without using the full yii2 framework.
但我不确定你是否可以在不使用完整的yii2框架的情况下使用它。
The way it works is that you put validation rules in your yii2 models (activerecord-style).
它的工作方式是将验证规则放在yii2模型中(activerecord-style)。
Core built in validators support both client and server side validation. If you create custom validator rules (always happens unless you do very basic forms). Then you can pick if you will do server side only or implement client side as well.
内置验证器的核心支持客户端和服务器端验证。如果您创建自定义验证器规则(除非您执行非常基本的表单,否则总是会发生)。然后,您可以选择是仅执行服务器端还是实现客户端。
You use a yii2 widget called activeform. You pass your model to activeform. It renders the form for you (it's flexible, and you don't have to render everything with it if you dont want to, it includes the javascript required to handle the validation etc.
您使用名为activeform的yii2小部件。您将模型传递给activeform。它为您呈现表单(它是灵活的,如果您不想,它不必使用它呈现所有内容,它包含处理验证所需的javascript等。
you define a yii2 controller and action to handle the server side form submission and pass the POST-data to your model. then you call the models validate() method to validate server side .. and if needed you can render the form again by passing the invalid $model to the activeform and it will display errors.
您定义了一个yii2控制器和操作来处理服务器端表单提交并将POST数据传递给您的模型。然后你调用模型validate()方法来验证服务器端..如果需要你可以通过将无效的$ model传递给activeform来再次渲染表单,它将显示错误。
It also has ajax-capabilities, not sure exactly how it works, but it still does client and server side validation.
它还具有ajax功能,不确定它是如何工作的,但它仍然进行客户端和服务器端验证。
Let me know if you try this and successfully extract only what is needed from yii2 to do this. I would like to use this part of yii2 without having the full yii2 framework.
如果您尝试这个并成功提取yii2所需的内容,请告诉我。我想在没有完整的yii2框架的情况下使用yii2的这一部分。