I am currently validating user input on server side (PHP). The client side sends XMLHttpRequest calls and marks invalid fields with red borders. Everything else is great except that I think it takes too long for the client to make a request and then notice that he filled something wrong. I think I should place some JavaScript validations as well so that the client does not need to wait for the request to finish.
However, I do not want to duplicate validation rules and code. Has anyone implemented validation on both sides so that you do not need to duplicate validation rules at least?
I am using Yii and plain old JavaScript with jQuery if that matters.
Edit: I also find it tedious that the client may have a wrong time on his computer making JavaScript based datetime checks bad. This means I would need to give the right datetime from the server to the script first.
I believe PEARs quick forms allow your to add validation for both client and server side at the same time.
Since you are using the Yii framework and Yii provides a fairly robust validation scheme I’d look at some way of extending the form generation framework to check the fields for a validator, then map each of the validation classes to a js function that you should be able to write quite quickly.
There also appears to be an extension that will do this for you : http://www.yiiframework.com/extension/jformvalidate/