[eluser]imn.codeartist[/eluser]
[quote author="Kolmiloikka" date="1276691324"]Hi!
I have a form which has 2 fields, hours(text input) and minutes(dropdown) which make total duration. Total duration must be positive. How can i validate this?
I have a form_validation rule:
Code:
$this->form_validation->set_rules("minutes", 'Minutes', 'required|callback_duration_is_positive');
And i have a callback (which obviously do not work atm):
Code:
function duration_is_positive($minutes) {
if ($minutes == 0) {
$this->form_validation->set_message('duration_is_positive', 'Duration has to be positive.');
return false;
}
else
return true;
}
Can i pass hours to callback somehow?
Thank you very much![/quote]
Yes you can pass hours to call back
Code:
function duration_is_positive($minutes) {
$hours=$this->input->post('your_hours'); //This is how you call other fields in callback
if ($minutes == 0) {
$this->form_validation->set_message('duration_is_positive', 'Duration has to be positive.');
return false;
}
else
return true;
}