Welcome Guest, Not a member yet? Register   Sign In
Validation question
#1

[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> &lt;input type="text" name="Dose" id="Dose"&gt;<br />
<label for="Other">Other:</label> <select name="Other" id="Other">
<option value="">&nbsp;</option>
<option value="Declined">Declined</option>
<option value="Not Available">Not Available</option>
</select>
&lt;/form&gt;

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).
#2

[eluser]wiredesignz[/eluser]
The syntax is $rules['Dose'] = 'callback_dose'; However callbacks won't run on empty fields.

One solution would be to have a hidden field also named `dose` with a dummy value you can check against.
#3

[eluser]jdgiotta[/eluser]
I've followed some other threads about how to validate if a file is supplied for upload.
So what I've done is create a dummy hidden field:
Code:
&lt;input type="hidden" name="video_d" /&gt;
I then set rules/fields:
Code:
$rules['video_d'] = "callback_check_video";
...
$fields['video_d'] = 'video';
...

Now all I've done was make a function called check_video with a simple echo and exit to say "Hey I'm called!", but it never executes.

If I'm making my assumptions right, then according to this thread the dummy field must have a value in order for callback to execute. Am I correct?
#4

[eluser]DanielJay[/eluser]
That is my understanding now. I think what you would have to do is set your video_d value to 1 or something and then it should run.




Theme © iAndrew 2016 - Forum software by © MyBB