![]() |
Validation failing on empty fields even when not required - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Validation failing on empty fields even when not required (/showthread.php?tid=78646) |
Validation failing on empty fields even when not required - motownphilippe - 02-19-2021 I keep my validation rules in App/Config/Validation I have one of my rules set as: PHP Code: 'topic' => [ When the 'topic' field is let blank it fails validation despite 'required' not being set as a rule. If I remove the validation rule completely then the validation passes as it should, but this means that there is no validation on the field. The same behaviour exists on all my fields. I thought fields were not required by default (otherwise, why would we need the 'required' rule). I would really appreciate any explanation or suggestion. RE: Validation failing on empty fields even when not required - motownphilippe - 02-19-2021 Ah, just found 'permit_empty' rule which achieves the behavior I'm after. So, 'required' is not necessary on when many of the other rules are set. I think this is a change from Code Igniter 3. RE: Validation failing on empty fields even when not required - kenjis - 02-19-2021 I got the same situation with `valid_email`. It seems CI4 format validation rules do not permit empty string. So we must add `permit_empty` if we want to permit empty. |