![]() |
Validate multiple input in CI 4 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Validate multiple input in CI 4 (/showthread.php?tid=78790) |
Validate multiple input in CI 4 - ciddict - 03-10-2021 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. RE: Validate multiple input in CI 4 - demyr - 03-11-2021 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? RE: Validate multiple input in CI 4 - ciddict - 03-11-2021 @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 RE: Validate multiple input in CI 4 - InsiteFX - 03-11-2021 CodeIgniter 4 User Guide - Running Multiple Validations permit_empty - Allows the field to receive an empty array, empty string, null or false. RE: Validate multiple input in CI 4 - ciddict - 03-11-2021 @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. RE: Validate multiple input in CI 4 - kenjis - 03-11-2021 See https://codeigniter4.github.io/CodeIgniter4/libraries/validation.html#validating-keys-that-are-arrays RE: Validate multiple input in CI 4 - ciddict - 03-12-2021 @kenjis, Can you please implement it for my case? I don't understand how to make this from your link: https://codeigniter4.github.io/CodeIgniter4/libraries/validation.html#validating-keys-that-are-arrays RE: Validate multiple input in CI 4 - kenjis - 03-12-2021 I never tried it, but in your case: PHP Code: // The data to test: RE: Validate multiple input in CI 4 - ciddict - 03-13-2021 @kenjis, it worked. Thank you so much. RE: Validate multiple input in CI 4 - pippuccio76 - 04-03-2023 (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= |