Creates a dropdown list of states from the US, US Territories and Canada
Requirements ¶
- Yii 1.1.x
Install ¶
- Extract to extensions directory
- Add following to the import section of the main config
- 'application.extensions.states.*'
Usage ¶
$options = array(
"name" => "thestates",
"seperateCountries" => true,
"selected" => "VA",
);
$htmlOptions = array(
"prompt" => "Please select a state",
);
echo States::render(array("US","canada","us territories"), $options, $htmlOptions);
Active Form
$form->dropDownList($address, 'state', My_States::getStates(array("US"), true),
array('prompt' => 'State', 'class' => 'abc', 'style' => "width:75px;")),
thank you
Thanks for your extension. It helps me alot!
help
How do I use this extension ?
Usage
Hi Ruaan,
Did you not see the install and usage sections above?
What problems are you running into?
@dungdeveloper, I'm glad that the extension helped you out.
Thank you
Got it to work :-) It was simple . Thank you for the quick response and awesome extension..
Thanks for the extension
My question is do I store this in database as varchar or text, enum?
Form help
Sorry, but I am a severe noob. How do I put this in my form? Is it a $form->dropDownList? If so, does the usage code go in the CHtml::listData section? Thanks.
Form help
@oneflatfoot,
as of now this just extends the CApplicationComponent and returns CHtml::dropDownList()
You can put it in anyform and just deal with the data in the controller. The data will be sent in the post.
Let me know if you need anymore help.
ability to use the states in CActiveForm widgets
Hi cfletcher1856,
I made the following changes to this extension inorder to
class My_States extends States { public static function getStates(array $countries, $shortName = FALSE) { $return = array(); if (in_array('US', $countries)) $return += self::$us; if (in_array('CANADA', $countries)) $return += self::$canada; if (in_array('US TERRITORIES', $countries)) $return += self::$us_territories; if ($shortName) foreach ($return as $key => &$value) $value = $key; return $return; } }
and
- private static $us = array( + protected static $us = array( ... - private static $us_territories = array( + protected static $us_territories = array( ... - private static $canada = array( + protected static $canada = array(
With this, I could use the function in a way consistent with the other form element calls:
$form->dropDownList($address, 'state', My_States::getStates(array("US"), true), array('prompt' => 'State', 'class' => 'abc', 'style' => "width:75px;")),
You could consider adding this to the extension.
Thanks,
Alan
Update
Thanks Alan, your changes were added to 1.1
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.