![]() |
Validation rule required on multiple select field always fails - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19) +--- Thread: Validation rule required on multiple select field always fails (/showthread.php?tid=65494) |
Validation rule required on multiple select field always fails - Nikos_Kontis - 06-18-2016 Hello everyone, I don't know if this is a bug or something that I missed in the upgrade guide from CI2 to CI3, but here goes... My problem is related to validating with the "required" rule a SELECT field that can capture multiple values. The code I was using until I migrated CI3 seemed to work properly, but after I migrated to CI3 it fails to pass an if no data are being send send from the field. If I remove the required validation rule, the whole logic works properly and the data are saved/updated properly in the database. HTML: Code: <select id="groups" name="groups[]" multiple="multiple" > and the validation rule in the PHP controller: PHP Code: $rules = [ I appreciate any help or guidance, thanks. RE: Validation rule required on multiple select field always fails - cartalot - 06-18-2016 unless i can't find it - there is no ci validation rule called "required_select" . and if that is true, and it was working before - then somewhere in your previous app there was custom code. i googled that term and there are references to it in stackoverflow. is it possible you created a My_form_validation in CI 2 and then didn't bring it over? anyways google it and you will see what i'm talking about. the rule for required is just 'required' . and you might need to put brackets on the field name like 'field' => 'groups[]' but i've never worked with a multiple select field so i'm not sure if that is correct. RE: Validation rule required on multiple select field always fails - Nikos_Kontis - 06-18-2016 My bad, I meant 'rules' => 'required' in the example PHP code (I edited my initial question). Any how I found the solution to my problem, I had to change the name of the field in the rules. So instead of usings 'groups' Code: $rules = [ is used 'groups[]' PHP Code: $rules = [ |