简体   繁体   中英

need some help figuring out how to approach this validation

I am using codeigniter for my form validation. I have two select fields named parent_male and 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM