Where to find the select html tag for countries on the account create page in Magento 1.9.0.1

1.3k views Asked by At

I want to show country selection box in customer account create page, so I used this code:

<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>

Which I get it by default.

But it show first option value blank and it shows blank when I selected. So I want to show select country text in place of blank option value. For that I need the page from where it is inherited.

3

There are 3 answers

0
Chandresh On

You can find the getCountryHtmlSelect function for account create page at below path

\app\code\core\Mage\Directory\Block\Data.php

0
Mageworx On

In case you aren't using custom blocks, the standard block Mage_Customer_Block_Form_Register uses the selection of countries from the Mage_Directory_Block_Data block.

This block, in turn, uses Mage_Core_Block_Html_Select to create the selection. So here you can learn how to form it the right way.

0
Patryk On

Blank option value is there by default if you don't have any country enabled. Pleas enable one in backend to show (it will be by default choose and can be your default store country). You can set first value to ID of country to be set by default.

Where this select come from:

/app/code/core/Mage/Directory/Block/Data.php

There is function public function getCountryHtmlSelect($defValue=null, $name='country_id', $id='country', $title='Country')`

And in this function there is created block:

$html = $this->getLayout()->createBlock('core/html_select')

Under it you see parameters and there is unfortunally hard coded class. If you need: $defValue=null can be set to country ID to show something other than blank option.

This give you blank option:

    if (is_null($defValue)) {
        $defValue = $this->getCountryId();
    }

You can for example in your template use:

<?php echo $this->getCountryHtmlSelect("PL") ?> // GET POLAND COUNTRY