I am using codeigniter for my form validation. I have two select fields named parent_male a开发者_如何转开发nd parent_female. I would like to have a validation callback to check both the parent_male and parent_female in my database to see if it exists. I already have a previous callback function that does just that, but with only one field. I would like to check the two field values against the database, except I am not sure how to approach this idea. Any help/ideas are greatly appreciate! Thank you.
-Rich
You can define your callback as:
function isparent($parent) {
$result = FALSE;
/* do your stuff to check $parent is a valid parent and then ... */
return $result;
}
and the rules can be set as
$this->form_validation->set_rules('parent_male', 'Male parent', 'callback_isparent');
$this->form_validation->set_rules('parent_female', 'Female parent', 'callback_isparent');
In that way you use the same callback for both fields.
精彩评论