Validate multiple input in CI 4 |
Hi,
This is the code in my controller: PHP Code: $fields = array( I'm getting this output: Code: Array Looking for help. Thanks in advance.
Well, actually not sure why you have tried such complicated coding but I would go simpler
PHP Code: $user_id => $this->request->getVar('user_id'); Btw, can you write more specifically what was your need and desired result?
@demyr,
You've used raw code for validation (not CI). Simply, it's working well with, PHP Code: $fields = array( But if there has multiple input with the single field like checkbox, the validation isn't working. With this code: PHP Code: $fields = array( It's shouldn't show this error, Code: {"user_id[]":"The user_id[] field is required."} While there has values, Code: Array
CodeIgniter 4 User Guide - Running Multiple Validations
permit_empty - Allows the field to receive an empty array, empty string, null or false. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
@InsiteFX,
Thanks. But if I add permit_empty and no value found, it won't show error. I mean, if this code: PHP Code: print_r($this->request->getPost("user_id")); shows: Code: Array () Then the validation should show the error what I want. But after adding permit_empty it won't show error.
@kenjis, Can you please implement it for my case? I don't understand how to make this from your link: https://codeigniter4.github.io/CodeIgnit...are-arrays
I never tried it, but in your case:
PHP Code: // The data to test:
(03-13-2021, 02:15 AM)ciddict Wrote: @kenjis, it worked. Thank you so much. hi , is there a way to set_value on multiple field? i try to create a for cicle and use value='<?=set_value("serial_number[$i]")?>' but value is empty edit: work , for start to 1 array start to 0 now i start for from 0... How can i validate min_length only if is set the field ( on multiple field)? this is my rules : Code: $rules= |
Welcome Guest, Not a member yet? Register Sign In |