[eluser]dustinsenos[/eluser]
So I've spent some time and found a solution that doesn't require custom code and is quite straight forward.
Synopses:
Store each input's value in a private instance variable through a custom _callback applied to each input and then validate the combination of their values in a hidden input's custom _callback.
Proof of Concept:
views/ageView.php
Code:
<form>
<input type="text" name="ageMonth" value="<?= set_value('ageMonth'); ?>" />
<input type="text" name="ageDay" value="<?= set_value('ageDay'); ?>" />
<input type="text" name="ageYear" value="<?= set_value('ageYear'); ?>" />
<input type="hidden" name="finalAgeValidation" />
</form>
config/form_validation.php:
Code:
$config = array('ageCheck' => array(array(
'field' => 'ageMonth',
'label' => 'Month Born',
'rules' => 'trim|required|max_length[2]|numeric|callback_monthCheck'
),
array(
'field' => 'ageDay',
'label' => 'Day Born',
'rules' => 'trim|required|max_length[2]|numeric|callback_dayCheck'
),
array(
'field' => 'ageYear',
'label' => 'Year Born',
'rules' => 'trim|required|min_length[4]|max_length[4]|numeric|callback_yearCheck'
),
array(
'field' => 'finalAgeValidation',
'label' => 'Age Validation',
'rules' => 'callback_finalAgeValidation'
)));
controller/AgeController.php
Code:
<?php
class Age extends Controller {
private $month;
private $day;
private $year;
public function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->form_validation->run('ageCheck');
}
public function monthCheck($month)
{
$this->month = $month;
}
public function dayCheck($day)
{
$this->day = $day;
}
public function yearCheck($year)
{
$this->year = $year;
}
public function finalAgeValidation()
{
echo '<h1>Age:</h1>';
echo '<h2>Month: ' . $this->month . '</h2>';
echo '<h2>Day: ' . $this->day . '</h2>';
echo '<h2>Year: ' . $this->year . '</h2>';
if (check what you have with your values...)
{
$this->form_validation->set_message('finalAgeValidation', "You must be born in the month of May!");
return false;
}
return true;
}
?>
Hope that helps!
Cheers,
Dustin