Performing client and server side validation using jQuery and CodeIgniter

What is the correct way to check both client side and server side using jQuery and CodeIgniter? I am using jQuery form plugin for submit form. I would like to use the jQuery validation plugin ( http://docs.jquery.com/Plugins/Validation ) to validate on the client side and validate the CodeIgniter form on the server side. However, these two do not seem to gel together (or I can’t shave my head). Can someone help please? Regardless of client-side validation or server-side validation, the user should see a consistent user interface that displays error messages next to the input fields.

[Edit] It looks like I can pass errors on the server side to show Errors (), like here ( http://forum.jquery.com/topic/jquery-validation-showerrors-error ). However, if I perform additional checks on the server side (for example, checks if the username has already been completed), which are not in the client rules, then the check plugin will clear these check messages when user tabs exit these fields.

+4
source share
4 answers

As already mentioned, these are two different things.

Just create your client side validation in jQuery, if that passes, pass it to the form controller and check the / xss check filtering there.

Try http://formigniter.org/ , it will build your form (view), model, sql and controller with validation included in it. Easy peasy ...

Hope this helps.

+3
source

What's not clear? Each method will be different.

At a high level, essentially, you will use client-side validation before submitting form data. If client-side validation is validated, submit the form and start the validation server. If the server-side check fails, it should print an error message when the page is re-rendered, as well as if the check / save was completed successfully.

0
source

Don't you want to duplicate server-side validation rules and messages in your client-side validation? This is not supported in the underlying CodeIgniter framework.

I looked at the CodeIgniter wiki and someone wrote a library to generate javascript from server side validation rules . I have not tried. But it may be what you are looking for.

0
source

I wanted to do the same thing, it can be done, but it is difficult. You can create reliable server-side validation methods that you call remotely using Ajax. If javascript is not enabled, you simply use the usual server-side validation methods without remote calls. Thus, you will have only one code base for verification.

However, the problem is that your client check will be much slower because it must constantly interact with the inner end. An even bigger problem is that you cannot use some powerful client validation libraries, since all of them assume that the verification is performed on the client and not remotely.

I just refused it. I had to duplicate my validation logic and error message on client and server. This is not ideal, but is best for users, and you can use large front-end libraries.

0
source

Source: https://habr.com/ru/post/1304001/


All Articles