Question

I hope you all are doing well,

I am working in magento 1.6.0.1. My current site is just for USA, so in registration page don't need country drop down list,and must display all USA state in state drop down list.

For now I set country value "US" in hidden field.

So how can I get all USA state in state drop down list

Was it helpful?

Solution

Add this in register.phtml to display all states of US:

                <div class="field">
                    <label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
                    <div class="input-box">
                        <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select">
                            <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                    <?php
                    $this->setData('country_id','US'); // or 'FR'..., default is 'US'
                    $regions     =   $this->getRegionCollection();
                    foreach($regions as $region)
                    {
                        echo "<option value=$region[name]>".$region['name'] . "</option>";
                    }
                    ?>

                        </select>
                        <script type="text/javascript">
                        //<![CDATA[
                            $('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
                        //]]>
                        </script>

                        <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;"   />
                    </div>
                </div>
            </li>
            <li class="fields">
                  <div class="field">
                    <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
                    <div class="input-box">
                        <?php echo $this->getCountryHtmlSelect() ?>
                    </div>
                </div>

and replace bottom javascript with:

  <script type="text/javascript">
        var dataForm = new VarienForm('form-validate', true);
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
    </script>

Hope it will help

OTHER TIPS

from Country and States in Magento :

 <script type="text/javascript">
        var dataForm = new VarienForm('form-validate', true);
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
    </script>

This is worked for me.

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

                        </select>                       

                        </div>
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top