Validate input of two possible arrays - 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: Validate input of two possible arrays (/showthread.php?tid=75346) |
Validate input of two possible arrays - dwlamb - 01-28-2020 The code below depicts a form for which I am trying to create validation rules. The form is for adding or removing users from a group. PHP Code: <form action="http://some_site.com/form_edit_group" method="post" accept-charset="utf-8"> It is possible after clicking submit, $_post will have an array "add_to_group[]", "remove_from_group[]", both arrays or neither array in the event the administrator forgets to click on a user in either select list. The validation rules I wish to set are:
PHP Code: $this->form_validation->set_rules('username', 'Username', 'callback_username_check'); such as 'username'. I want a rule with callback function that will examine $_post to see if either array exists. Is there another method? RE: Validate input of two possible arrays - jreklund - 01-29-2020 You can set an custom callback on whatever field you want. For e.g. on the group_id. And in that custom callback grab both arrays and do your checks. Post are always available (in controller and model). PHP Code: public function check_groups() And depending on what fails, send custom error codes. PHP Code: $this->form_validation->set_message('check_groups', 'Add to group error'); |