Arvind Jha
Arvind Jha

Reputation: 67

how can i get us all state in magento?

   <li class="state">
        <label for="State" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
        <div class="input-box">
            <select id="State" name="State" title="<?php echo $this->__('State') ?>" class="validate-select" style="display:none;">
            <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
             </select>

             <input type="text" id="State" name="State" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
       </div>
  </li>

Upvotes: 1

Views: 947

Answers (2)

Pavlo Zamoroka
Pavlo Zamoroka

Reputation: 56

Use directory API instead of resource collection:

Mage::getModel('directory/region_api')->items('US')

Upvotes: 1

hardayborlar
hardayborlar

Reputation: 379

You can use get the list of states as:

Code

 <li class="state">
        <label for="State" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
        <div class="input-box">
            <select id="State" name="State" title="<?php echo $this->__('State') ?>" class="validate-select" style="display:none;">
            <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
               <?php 
                $regionCollection = Mage::getModel('directory/region')->getResourceCollection()
                                    //->addCountryFilter()
                                    ->load();
                foreach($regionCollection as $region){
                  echo "<option value=$region[name]>".$region['name'] . "</option>";
                }
                ?>
             </select>

             <input type="text" id="State" name="State" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
       </div>
  </li>

Note: this code comment: //->addCountryFilter() can be uncommented if you want to filter by specific country e.g 'US' or 'CA' or 'FR' etc

Upvotes: 2

Related Questions