Ajax and ci4 validation |
Just wondering if it is possible to use ci4’s from validation instead using say jquery’s validate()? If so, is there an example anywhere? I assume not possible as cannot see an example but thought I would still ask. Thank you.
Can you explain more precisely. For example, I do not understand what you are talking about.
(05-16-2022, 06:28 PM)iRedds Wrote: Can you explain more precisely. For example, I do not understand what you are talking about. Normally, I place my validation in the Model (sometimes place in controller) something like this; PHP Code: $category = $this->model->find($category_id); My rules are somethin like; PHP Code: protected $validationRules = [ How would like use the above in case of using ajax. Is is possible? (05-16-2022, 05:58 PM)spreaderman Wrote: Just wondering if it is possible to use ci4’s from validation instead using say jquery’s validate()? If so, is there an example anywhere? I assume not possible as cannot see an example but thought I would still ask. Thank you.Jquery's validate() method is a client-side validation. CodeIgniters form validation is server-side validation. There is a BIG difference. You should always use server-side validation for security reasons, even if you use client-side validation. Never trust user input. Client-side validations in general used to reduce the number of useless calls to the server. For example, in your site you have a signup to newsletter form with one input field to enter email address. If there is no client-side validation user may send you empty form, or just text or number instead of email, or just send you invalid email address. All this calls is useless and gives extra load to the webserver.
Don't use redirect.
PHP Code: return $this->response->setJson(['errors' => $this->model->errors()]);
Thank you very much for all the tips! Super helpful. Have read more on the topic. I am happy to have learnt the advice about keeping the validation on the server. I would have hated to have invested weeks into client side validation. Thanks.
|
Welcome Guest, Not a member yet? Register Sign In |