Welcome Guest, Not a member yet? Register   Sign In
Check part of string is in_array()
#4

[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;
                }
            }


Messages In This Thread
Check part of string is in_array() - by El Forum - 05-24-2008, 07:47 PM
Check part of string is in_array() - by El Forum - 05-24-2008, 07:59 PM
Check part of string is in_array() - by El Forum - 05-24-2008, 08:03 PM
Check part of string is in_array() - by El Forum - 05-25-2008, 06:31 AM
Check part of string is in_array() - by El Forum - 05-25-2008, 06:38 AM
Check part of string is in_array() - by El Forum - 05-25-2008, 06:42 AM
Check part of string is in_array() - by El Forum - 05-25-2008, 06:45 AM
Check part of string is in_array() - by El Forum - 05-25-2008, 06:47 AM
Check part of string is in_array() - by El Forum - 05-25-2008, 02:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB