Welcome Guest, Not a member yet? Register   Sign In
validating an "edit" form
#12

[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.


Messages In This Thread
validating an "edit" form - by El Forum - 08-13-2008, 12:44 AM
validating an "edit" form - by El Forum - 08-13-2008, 12:57 AM
validating an "edit" form - by El Forum - 08-13-2008, 02:05 AM
validating an "edit" form - by El Forum - 08-13-2008, 02:52 AM
validating an "edit" form - by El Forum - 08-13-2008, 02:42 PM
validating an "edit" form - by El Forum - 08-13-2008, 02:46 PM
validating an "edit" form - by El Forum - 08-13-2008, 07:48 PM
validating an "edit" form - by El Forum - 08-14-2008, 12:33 AM
validating an "edit" form - by El Forum - 08-14-2008, 12:34 AM
validating an "edit" form - by El Forum - 08-14-2008, 08:53 AM
validating an "edit" form - by El Forum - 08-14-2008, 08:55 AM
validating an "edit" form - by El Forum - 08-14-2008, 09:21 AM
validating an "edit" form - by El Forum - 08-14-2008, 09:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB