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">
<p>Add to group. Hold Ctrl-key and click for selecting more than one.</p>
<select name="add_to_group[]" class="add_to_group" multiple size="4">
<option value="3">Jane Smith</option>
<option value="6">Jim Jones</option>
<option value="7">Casey Jones</option>
</select>
<p>Existing members of group. To remove hold Ctrl-key and click for selecting more than one:</p>
<select name="remove_from_group[]" class="remove_from_group" multiple size="4">
<option value="1">Bill Clinton</option>
<option value="4">James Carter</option>
<option value="5">John Kennedy</option>
</select>
<input type="hidden" name="group_id" value="3">
<input type="submit" name="submit" value="Submit" />
</form>
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:
- whether $_post contains "add_to_group[]" or "remove_from_group[]"
- if one or both of those arrays exist, perform checks on the data within the arrays <- these I have figured what to do
Looking through the documentation for Form Validation, I think the answer is a custom callback put can't figure out how to submit $_post in the rule. A form validation rule holds a key within $_post:
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?