Welcome Guest, Not a member yet? Register   Sign In
A small helper function to compliment the existing form dropdown helper function.
#1

[eluser]Basketcasesoftware[/eluser]
I discovered the documentation was vague on the arguments of the form_dropdown helper function about the item selected argument. I hoped for the best and fed it the display value of the entry I wanted as my default selection. Actually it goes off of the key instead. Since I'm working with rather long lists of option groups (196 countries by region) I needed something a little better. This is a first draft. It functions quite well as far as I've been able to test it.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('select_search'))
{
    function select_search($needle,$haystack)
        {
            $selected=array_search($needle,$haystack);

            if ($selected) return $selected;

            foreach ($haystack as $key => $val)
            {
                if(is_array($val))
                {
                    $selected=array_search($needle,$val);
    
                    if($selected) return $selected;
                }
            }
          
           return NULL;
        }
}
?>

I'm open for corrections and improvements. Smile


Messages In This Thread
A small helper function to compliment the existing form dropdown helper function. - by El Forum - 06-14-2011, 12:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB