0

我想在时事通讯中显示国家和州字段。对于我使用此编码的国家/地区:-

<?php $_countries = Mage::getResourceModel('directory/country_collection')
                                ->loadData()
                                ->toOptionArray(false) ?>
 <?php if (count($_countries) > 0): ?>
                       <label for="country"><?php echo $this->__('Country') ?></label>
                           <select name="country" id="newsletter">
                                <option value="">-- Please Select --</option>
                                 <?php foreach($_countries as $_country): ?>
                                    <option value="<?php echo $_country['value'] ?>">
                                                    <?php echo $_country['label'] ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                 <?php endif; ?>

它显示国家/地区列表,但我还想根据所选国家/地区显示状态下拉列表,如果未定义状态,则它将显示文本框,如默认 magento 功能。我试试这个代码: -

<div class="input-box">
                            <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
                                <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                            </select>
                            <script type="text/javascript">
                            //<![CDATA[
                                $('region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
                            //]]>
                            </script>
                            <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
                        </div>

但它显示错误。非常感谢任何帮助。

4

1 回答 1

1

我得到了解决方案: - 国家的下拉应该是: -

 <?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>

状态应该是这样的:--

 <label for="state"><em>*</em><?php echo $this->__('State/Province') ?></label>
                         <select style="" title="State/Province" name="region_id" id="region_id" defaultvalue="" class="required-entry validate-select" style="display:none;">
                                <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                         </select>
                   <script type="text/javascript">
                   //<![CDATA[
                       $('region_id').setAttribute('defaultValue',  "<?php echo $this->getEstimateRegionId() ?>");
                   //]]>
                   </script>
                   <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />

脚本是:-

 <script type="text/javascript">
    //<![CDATA[
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
    //]]>
    </script>
于 2013-01-08T04:23:23.667 回答