Welcome Guest, Not a member yet? Register   Sign In
Automated US State dropdown
#1

[eluser]Iverson[/eluser]
I got tired of recreating a dropdown so I made a view that I can just include in my application. You can use the following variables:

Code:
<?php

// Optional variables
$config['name'] = 'element_name';        // sets the name attribute to "element_name"
$config['id'] = 'element_id';            // if not specified, the element will have the same name and id
$config['class'] = 'fancy_select';       // set the class attribute to 'fancy_select'

$config['multiple'] = TRUE;              // makes the menu a multiple select type
$config['selected']['XX'] = ' selected="selected"';        // sets "XX" to be selected
$config['selected']['XY'] = ' selected="selected"';        // sets "XY" to be selected. Also, the menu becomes a multiple select. No need to use $config['multiple']
$config['size'] = 25;                    // Sets the multiple select menu size


echo $this->load->view('state_dropdown', $config, TRUE);

This can easily be ported into a plugin or helper but I just didn't feel like it at the current moment Smile
#2

[eluser]PurdueKenny[/eluser]
Hey, thanks for this! Makes my life much easier; however, I'm getting an error saying that the element(); function is not found. Specifically on line 40

$select_open = '<select id="' . $id . '" name="' . $name . '"' . element('', $selected, '') . $class;



Did I need to do something that I haven't done yet?
#3

[eluser]Iverson[/eluser]
All you need to do is load the array helper.

http://ellislab.com/codeigniter/user-gui...elper.html
#4

[eluser]gscharlemann[/eluser]
Thanks for putting this together. You saved me a bunch of time.

I noticed the setting:
Code:
$config['multiple'] = FALSE;
didn't work (it still rendered a dropdown allowing multiple selections - even with size = 1). commenting out the statement (e.g. not declaring $config['multiple'] at all) fixed that.




Theme © iAndrew 2016 - Forum software by © MyBB