views:

49

answers:

2

Hi everyone,

I am using the CI validation class to do server-side validation and Jquery validation to do client-side validation. Is there some way I can leverage the CI validation and form building, so that when it is creating the form elements it creates them with class="<equivalent of CI validation rules>"? This way, if I change the valiation rules for an element I only have to do it in the CI rules and it automatically changes for Jquery.

Thanks,

Lemaint

+1  A: 

There is no out of the box solution that i know of out there to do this. You would have to create one yourself.

It would have to be a config file that maps what the codeigniter validation is called to the jquery equivalent and then that would have to be parsed for each field.

Tom Schlick
+1  A: 

You could make ajax calls back to CI for validation using $.ajax or $.post, that way you only have to create your validation rules in CI.

Here's an example I found to get you started: http://stackoverflow.com/questions/2331389/jquery-post-codeigniter-validation/2331527#2331527


Is there a way to map CodeIgniter Validation class to Jquery validation?

Not built-in. Not sure best way to approach this, but you could put all your rules in a validation config file and somehow get your jQuery to parse that file for validation rules when needed.

Mitchell McKenna
Thanks, that's a very good idea.
lemiant