Validation: one of two field required - 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: Validation: one of two field required (/showthread.php?tid=78426) |
Validation: one of two field required - Codinglander - 01-18-2021 Hello. I have a form in which two fields are related. I want at least one of the two fields to be filled out. It is also conceivable that both are filled in, but not that neither is filled out. Is there a validation rule for this? Or can someone help me with a solution? Greetings, Kigh ... RE: Validation: one of two field required - kleber - 01-18-2021 https://codeigniter.com/userguide3/libraries/form_validation.html#callbacks-your-own-validation-methods I think you can create your own validation rule for this case. Or you can follow the code below. I think you can do that on CI4 too. PHP Code: if(!isset($_POST['field_one']) and !isset($_POST['field_two'])){ RE: Validation: one of two field required - Codinglander - 01-18-2021 Hmmm... okay, today afternoon I#ll try it... RE: Validation: one of two field required - AndresHDZ - 01-19-2021 For CI 4: PHP Code: if($this->request->getPost('field_one') == '' && $this->request->getPost('field_two')){ Where $error_msg contains your error. |