[eluser]xwero[/eluser]
Related fields are a big gap in the vailidation library but it's very difficult to have solution that fits almost all scenarios.
The easiest solution would be to add a key to the POST global and check which field is filled in and assign that value to the new key.
Code:
if($_POST['field1'] != '')
{
$_POST['joined_field] = $_POST['field1'];
}
if($_POST['field2'] != '' && $_POST['joined_field] == '')
{
$_POST['joined_field] = $_POST['field2'];
}
if($_POST['field3'] != '' && $_POST['joined_field] == '')
{
$_POST['joined_field] = $_POST['field3'];
}
$rules['joined_field'] = 'required'; // change to required_one (see below)
This gives you a bit of trouble with the error message as it is meant for one field and setting a custom message will change it for all other fields that use the required rule too. To circumvent this you can add to the MY_Validation.php file a method named required_one which as following code
Code:
function required_one($str)
{
return $this->required($str);
}
So it's actually an alias of the required method. Now the only thing you have to do is add a
Code:
$lang['required_one'] = "Filling in one of these fields, %s, is required.";
to the language file and you are good to go.