[eluser]DanielJay[/eluser]
I am working on creating a form and want to use the validation library. I have setup the code for the validation and even extended the validation class. My problem is that I have 2 fields that I need to count as "one" but cannot figure out a validation rule. There are a few other form elements in this form but I need to have one or the other of Dose or Other.
Code:
<form>
<label for="Dose">Dose:</label> <input type="text" name="Dose" id="Dose"><br />
<label for="Other">Other:</label> <select name="Other" id="Other">
<option value=""> </option>
<option value="Declined">Declined</option>
<option value="Not Available">Not Available</option>
</select>
</form>
I tried to create a rule on the Dose input and created a function in my extended validation class like:
Code:
public function dose($str)
{
$Other = $this->CI->input->post('Other');
if (empty($str) && empty($Other)) {
$this->set_message('dose', 'You must supply a Dose or select a value in Other');
return false;
}
return true;
}
Then used:
Code:
$rules['Dose'] = 'dose';
Any ideas?
I did try to make this dose function a callback and it did not run. The only way I was able to get this dose validation to run is if there was something in the dose field(which there may not be).