Consider the scenario of refactoring and reorganizing a very large PHP project that contains a lot of pages with forms.
I've already written a quite flexible and compact JS validation function (with regexs, custom expressions and so on), but I'd like to migrate to JQuery's validation for its more structured and clean approach.
Client-side validation is nice as it is immediately responsive and gives a great feel to the UI, but this also leaves me with the problem that client-side validation could easily be tampered with, so I thought to "mirror" the validation rules also on the PHP (server) side to make things even (integrating if possible filters and sanitizing of data to address injections and other malicious behaviours).
Do you feel that this approach is the best one? Any general suggestions for implementing this?
Is there some kind of tool, framework, or PHP class that can take charge of this duplication, avoiding the rewriting of every rule in PHP?
If not, I considered writing my own PHP class, with methods to add rule by rule and a method that echoes a JQuery validation mini-script or function, but I'm not sure if this could be a good approach and how to use it efficiently. Any suggestions for me?
Thanks in advance.