[eluser]codex[/eluser]
I thought the function in Validation.php would help with what I'm trying to achieve, but no luck yet. I may be on the wrong track so maybe there's someone else that sees a better solution.
I'm creating a module for dynamic form creation. Through the admin you can add and edit inputs of all sorts. The adding/editing also involves settings for validation, which is being written to the db as one string, just as it's done with regular validation settings: required|min_length[2]|alpha_numeric
To edit the input values I explode the validation string, check if the rule is in the array, and write the corresponding values to the 'edit'-form on screen:
Code:
# Any rules found?
if (! empty($data['input'][0]->input_validation_rules)) // This is the validation string
{
$ex = explode('|', $data['input'][0]->input_validation_rules);
# Required
$data['required'] = in_array('required', $ex) ? 1 : ''; // Works
# Alpha
if (in_array('alpha', $ex))
{
$data['allowed_chars'] = 'alpha'; // Works
}
else if (in_array('alpha_numeric', $ex))
{
$data['allowed_chars'] = 'alpha_numeric'; // Works
}
else if (in_array('alpha_dash', $ex))
{
$data['allowed_chars'] = 'alpha_dash'; // Works
}
# Min length
if (in_array('min_length[*]', $ex)) // This obviously won't work, but can you wildcard a string in php?
{
// The parameter needs to be set here
// $data['min_length'] = $param;
}
}