Reputation: 14573
Ajax validation support would also be a plus.
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.
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.
Is there anything else like this?
Upvotes: 2
Views: 1075
Reputation: 262
Yii2 does this pretty well.
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.
The way it works is that you put validation rules in your yii2 models (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.
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.
It also has ajax-capabilities, not sure exactly how it works, but it still does client and server side validation.
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.
Upvotes: 0
Reputation: 69967
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.
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.
Upvotes: 1