Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Country dropdown list, shows empty option value? 
 
Syndia
Member
 
Total Posts:  38
Joined:  2008-04-01
Netherlands, The
 

I have created a country dropdown list in my attributes list, but it returns a empty value, what happend, all other country dropdown lists, don’t have.

<option value="">-- Please Select --</option>
<
option value=""></option> <!-- Where comes this from? -->
<
option value="AF">Afghanistan</option>
I checked database, now empty values in it.
I used the code below to get my country array
public function getAllOptions()
    
{
        $options 
Mage::getResourceModel('directory/country_collection')->load()->toOptionArray();
        
array_unshift($options, array('value'=>'''label'=>Mage::helper('catalog')->__('-- Please Select --')));
        return 
$options;
    
}
When I print $options, it returns
Array
(
    
[0] => Array
        (
            
[value] => 
            
[label] => 
        )

    
[1] => Array
        (
            
[value] => AF
            [label] 
=> Afghanistan
        
)
...
Is there someone who can help me out? Thanks!
 
Magento Community Magento Community
Magento Community
Magento Community
 
parvezmac1
Jr. Member
 
Total Posts:  4
Joined:  2010-07-17
noida
 

Hi you can use below code to get country list.

$countryList Mage::getResourceModel(‘directory/country_collection’)  
->
loadData()  
->
toOptionArray(false);  
echo 
‘<pre>’;  
print_r$countryList);  
exit(
‘</pre>’);
http://www.phpflow.com
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top