国家,城市,州的邮政编码下拉列表

时间:2012-07-05 06:33:04

标签: drop-down-menu

我希望包含某些电子商务网站的国家/地区,城市,州和邮政编码,我希望它为: 如果我选择特定国家的特定国家城市,则仅列出。一旦城市被选中那个城市的状态被看到下拉,一旦城市被选中,那个城市的邮政编码就会在下拉列表中看到。 我在谷歌搜索,但找不到任何可靠的链接。任何人都可以帮我链接或建议。欢迎任何帮助。谢谢 我目前的代码:

<form class="clearboth" name="form" action="" method="post" onSubmit="return sign_up(this);">
    <input type="hidden" name="action" value="<?php echo $_GET['action']?>" />
     <h1>New User: Sign Up</h1>
               <ul class="input_field">
               <li><label>Username <span>*</span></label>
                <input name="username" class="input_textarea" id="username" size="25" req="1" valimessage="Username cannot be blank" 
                      valiclass="required" />
                        </li>   
               <li><label>First Name <span>*</span></label>
                   <input name="first_name" class="input_textarea" id="first_name" size="25" req="1" 
                      valimessage="First name cannot be blank" 
                      valiclass="required" />
                 </li>
               <li><label>Last Name <span>*</span></label>
                 <input name="last_name" class="input_textarea" id="last_name" size="25" req="1" valimessage="Last name cannot be blank" 
                      valiclass="required" />
                </li>
                   <li><label>Street address <span>*</span></label>
                    <input name="address1" class="input_textarea" id="address1" size="25" req="1" valimessage="Street Address cannot be blank" 
                      valiclass="required" />
                      </li>
                 <li><label>Street address 2</label>
                 <input name="address2" class="input_textarea" id="address2" size="25" />
                  </li>
                   <li><label>City <span>*</span></label>
                           <input name="city" class="input_textarea" id="city" size="25" req="1" valimessage="City cannot be blank" 
                      valiclass="required" />
                   </li>
                    <li><label>Country <span>*</span></label>
                          <select name="country" class="input_textarea">
                                <option 
                        value="NA">Please Select</option>
                                <option>Afghanistan</option>
                                <option>Albania</option>
                                <option>Algeria</option>
                                <option>American Samoa</option>
                                <option>Andorra</option>
                                <option>Angola</option>
                                <option>Anguilla</option>
                                <option>Antarctica</option>
                                <option>Antigua and Barbuda</option>
                                <option>Argentina</option>
                                <option>Armenia</option>
                                <option>Aruba</option>
                                <option>Australia</option>
                                <option>Austria</option>
                                <option>Azerbaijan</option>
                                <option>Bahamas</option>
                                <option>Bahrain</option>
                                <option>Bangladesh</option>
                                <option>Barbados</option>
                                <option>Belarus</option>
                                <option>Belgium</option>
                                <option>Belize</option>
                                <option>Benin</option>
                                <option>Bermuda</option>
                                <option>Bhutan</option>
                                <option>Bolivia</option>
                                <option>Bosnia and Herzegowina</option>
                                <option>Botswana</option>
                                <option>Bouvet Island</option>
                                <option>Brazil</option>
                                <option>British Indian Ocean Territory</option>
                                <option>Brunei Darussalam</option>
                                <option>Bulgaria</option>
                                <option>Burkina Faso</option>
                                <option>Burundi</option>
                                <option>Cambodia</option>
                                <option>Cameroon</option>
                                <option>Canada</option>
                                <option>Cape Verde</option>
                                <option>Cayman Islands</option>
                                <option>Central African Republic</option>
                                <option>Chad</option>
                                <option>Chile</option>
                                <option>China</option>
                                <option>Christmas Island</option>
                                <option>Cocos (Keeling)Islands</option>
                                <option>Colombia</option>
                                <option>Comoros</option>
                                <option>Congo</option>
                                <option>Cook Islands</option>
                                <option>Costa Rica</option>
                                <option>Cote D'Ivoire</option>
                                <option>Croatia</option>
                                <option>Cuba</option>
                                <option>Cyprus</option>
                                <option>Czech 
                                  Republic</option>
                                <option>Denmark</option>
                                <option>Djibouti</option>
                                <option>Dominica</option>
                                <option>Dominican 
                                  Republic</option>
                                <option>East Timor</option>
                                <option>Ecuador</option>
                                <option>Egypt</option>
                                <option>El Salvador</option>
                                <option>Equatorial 
                                  Guinea</option>
                                <option>Eritrea</option>
                                <option>Estonia</option>
                                <option>Ethiopia</option>
                                <option>Falkland 
                                  Islands (Malvinas)</option>
                                <option>Faroe 
                                  Islands</option>
                                <option>Fiji</option>
                                <option>Finland</option>
                                <option>France</option>
                                <option>France, Metropolitan</option>
                                <option>French Guiana</option>
                                <option>French 
                                  Polynesia</option>
                                <option>French Southern 
                                  Territories</option>
                                <option>Gabon</option>
                                <option>Gambia</option>
                                <option>Georgia</option>
                                <option>Germany</option>
                                <option>Ghana</option>
                                <option>Gibraltar</option>
                                <option>Greece</option>
                                <option>Greenland</option>
                                <option>Grenada</option>
                                <option>Guadeloupe</option>
                                <option>Guam</option>
                                <option>Guatemala</option>
                                <option>Guinea</option>
                                <option>Guinea-bissau</option>
                                <option>Guyana</option>
                                <option>Haiti</option>
                                <option>Heard and Mc Donald Islands</option>
                                <option>Honduras</option>
                                <option>Hong 
                                  Kong</option>
                                <option>Hungary</option>
                                <option>Iceland</option>
                                <option>India</option>
                                <option>Indonesia</option>
                                <option>Iran (Islamic 
                                  Republic of)</option>
                                <option>Iraq</option>
                                <option>Ireland</option>
                                <option>Israel</option>
                                <option>Italy</option>
                                <option>Jamaica</option>
                                <option>Japan</option>
                                <option>Jordan</option>
                                <option>Kazakhstan</option>
                                <option>Kenya</option>
                                <option>Kiribati</option>
                                <option>Korea, Democratic People's Republic 
                                  of</option>
                                <option>Korea, Republic of</option>
                                <option>Kuwait</option>
                                <option>Kyrgyzstan</option>
                                <option>Lao People's 
                                  Democratic Republic</option>
                                <option>Latvia</option>
                                <option>Lebanon</option>
                                <option>Lesotho</option>
                                <option>Liberia</option>
                                <option>Libyan Arab 
                                  Jamahiriya</option>
                                <option>Liechtenstein</option>
                                <option>Lithuania</option>
                                <option>Luxembourg</option>
                                <option>Macau</option>
                                <option>Macedonia, The 
                                  Former Yugoslav Republic of</option>
                                <option>Madagascar</option>
                                <option>Malawi</option>
                                <option>Malaysia</option>
                                <option>Maldives</option>
                                <option>Mali</option>
                                <option>Malta</option>
                                <option>Marshall 
                                  Islands</option>
                                <option>Martinique</option>
                                <option>Mauritania</option>
                                <option>Mauritius</option>
                                <option>Mayotte</option>
                                <option>Mexico</option>
                                <option>Micronesia, Federated States of</option>
                                <option>Moldova, Republic of</option>
                                <option>Monaco</option>
                                <option>Mongolia</option>
                                <option>Montserrat</option>
                                <option>Morocco</option>
                                <option>Mozambique</option>
                                <option>Myanmar</option>
                                <option>Namibia</option>
                                <option>Nauru</option>
                                <option>Nepal</option>
                                <option>Netherlands</option>
                                <option>Netherlands 
                                  Antilles</option>
                                <option>New Caledonia</option>
                                <option>New Zealand</option>
                                <option>Nicaragua</option>
                                <option>Niger</option>
                                <option>Nigeria</option>
                                <option>Niue</option>
                                <option>Norfolk 
                                  Island</option>
                                <option>Northern Mariana 
                                  Islands</option>
                                <option>Norway</option>
                                <option>Oman</option>
                                <option>Pakistan</option>
                                <option>Palau</option>
                                <option>Panama</option>
                                <option>Papua New Guinea</option>
                                <option>Paraguay</option>
                                <option>Peru</option>
                                <option>Philippines</option>
                                <option>Pitcairn</option>
                                <option>Poland</option>
                                <option>Portugal</option>
                                <option>Puerto 
                                  Rico</option>
                                <option>Qatar</option>
                                <option>Reunion</option>
                                <option>Romania</option>
                                <option>Russian 
                                  Federation</option>
                                <option>Rwanda</option>
                                <option>Saint Kitts and Nevis</option>
                                <option>Saint Lucia</option>
                                <option>Saint 
                                  Vincent and the Grenadines</option>
                                <option>Samoa</option>
                                <option>San 
                                  Marino</option>
                                <option>Sao Tome and 
                                  Principe</option>
                                <option>Saudi Arabia</option>
                                <option>Senegal</option>
                                <option>Seychelles</option>
                                <option>Sierra 
                                  Leone</option>
                                <option>Singapore</option>
                                <option>Slovakia (Slovak Republic)</option>
                                <option>Slovenia</option>
                                <option>Solomon 
                                  Islands</option>
                                <option>Somalia</option>
                                <option>South Africa</option>
                                <option>South 
                                  Georgia and the South Sandwich Islands</option>
                                <option>Spain</option>
                                <option>Sri 
                                  Lanka</option>
                                <option>St. Helena</option>
                                <option>St. Pierre and Miquelon</option>
                                <option>Sudan</option>
                                <option>Suriname</option>
                                <option>Svalbard and Jan Mayen Islands</option>
                                <option>Swaziland</option>
                                <option>Sweden</option>
                                <option>Switzerland</option>
                                <option>Syrian Arab 
                                  Republic</option>
                                <option>Taiwan, Province of 
                                  China</option>
                                <option>Tajikistan</option>
                                <option>Tanzania, United Republic of</option>
                                <option>Thailand</option>
                                <option>Togo</option>
                                <option>Tokelau</option>
                                <option>Tonga</option>
                                <option>Trinidad and Tobago</option>
                                <option>Tunisia</option>
                                <option>Turkey</option>
                                <option>Turkmenistan</option>
                                <option>Turks and 
                                  Caicos Islands</option>
                                <option>Tuvalu</option>
                                <option>Uganda</option>
                                <option>Ukraine</option>
                                <option>United Arab Emirates</option>
                                <option>United Kingdom</option>
                                <option 
                        selected="selected">United States</option>
                                <option>United 
                                  States Minor Outlying Islands</option>
                                <option>Uruguay</option>
                                <option>Uzbekistan</option>
                                <option>Vanuatu</option>
                                <option>Vatican City 
                                  State (Holy See)</option>
                                <option>Venezuela</option>
                                <option>Viet 
                                  Nam</option>
                                <option>Virgin Islands 
                                  (British)</option>
                                <option>Virgin Islands 
                                  (U.S.)</option>
                                <option>Wallis and Futuna 
                                  Islands</option>
                                <option>Western Sahara</option>
                                <option>Yemen</option>
                                <option>Yugoslavia</option>
                                <option>Zaire</option>
                                <option>Zambia</option>
                                <option>Zimbabwe</option>
                            </select>
                    </li>
                   <li><label>State <span>*</span></label>
                    <select name="us_state" class="input_textarea">
                                <option value="NA" 
                        selected="selected">Please Select</option>
                                <option>Alabama</option>
                                <option>Alaska</option>
                                <option>American Samoa</option>
                                <option>Arizona</option>
                                <option>Arkansas</option>
                                <option>Armed Forces 
                                  Africa</option>
                                <option>Armed Forces 
                                  Americas</option>
                                <option>Armed Forces 
                                  Canada</option>
                                <option>Armed Forces 
                                  Europe</option>
                                <option>Armed Forces Middle 
                                  East</option>
                                <option>Armed Forces 
                                  Pacific</option>
                                <option>California</option>
                                <option>Colorado</option>
                                <option>Connecticut</option>
                                <option>Delaware</option>
                                <option>District of 
                                  Columbia</option>
                                <option>Federated States Of 
                                  Micronesia</option>
                                <option>Florida</option>
                                <option>Georgia</option>
                                <option>Guam</option>
                                <option>Hawaii</option>
                                <option>Idaho</option>
                                <option>Illinois</option>
                                <option>Indiana</option>
                                <option>Iowa</option>
                                <option>Kansas</option>
                                <option>Kentucky</option>
                                <option>Louisiana</option>
                                <option>Maine</option>
                                <option>Marshall 
                                  Islands</option>
                                <option>Maryland</option>
                                <option>Massachusetts</option>
                                <option>Michigan</option>
                                <option>Minnesota</option>
                                <option>Mississippi</option>
                                <option>Missouri</option>
                                <option>Montana</option>
                                <option>Nebraska</option>
                                <option>Nevada</option>
                                <option>New 
                                  Hampshire</option>
                                <option>New Jersey</option>
                                <option>New Mexico</option>
                                <option>New 
                                  York</option>
                                <option>North Carolina</option>
                                <option>North Dakota</option>
                                <option>Northern 
                                  Mariana Islands</option>
                                <option>Ohio</option>
                                <option>Oklahoma</option>
                                <option>Oregon</option>
                                <option>Palau</option>
                                <option>Pennsylvania</option>
                                <option>Puerto 
                                  Rico</option>
                                <option>Rhode Island</option>
                                <option>South Carolina</option>
                                <option>South 
                                  Dakota</option>
                                <option>Tenessee</option>
                                <option>Texas</option>
                                <option>Utah</option>
                                <option>Vermont</option>
                                <option>Virgin 
                                  Islands</option>
                                <option>Virginia</option>
                                <option>Washington</option>
                                <option>West 
                                  Virginia</option>
                                <option>Wisconsin</option>
                                <option>Wyoming</option>
                            </select>
                   </li>         

                         <li><label>Zip Code <span>*</span></label>
                    <input name="zip" class="input_textarea" id="zip" size="25" req="1" 
                      valimessage="Invalid Zip code" 
                  valiclass="zip" />
                  </li>
                   <li><label>Phone</label>
                      <input name="phone" class="input_textarea" id="phone" size="25" />
                   </li>
                    <li><label>Fax</label>
                   <input name="fax" class="input_textarea" id="fax" size="25" />
                 </li>
                           <li><label>Email address<span>*</span></label>
                      <input name="email" class="input_textarea" id="email" size="25" req="1" 
                      valimessage="Invalid email address" 
                      valiclass="email" />
                 </li>
                           <li><label>Password <span>*</span></label>
                         <input name="password" type="password" class="input_textarea" id="password" size="25" req="4" 
                      valimessage="not sufficent password lenghth" 
                      valiclass="required" />
                      </li>
                           <li><label>Verify Password</label>
                           <input name="password2" type="password" class="input_textarea" id="password2" size="25" />
                        </li>
                        <li><label>&nbsp;</label>* indicates required fields.</li>

                          <li><label>&nbsp;</label>
                          <input type="submit" value="Sign up" name="btn_signup"  class="red_btn"/>
                          </li>
                          </ul>

1 个答案:

答案 0 :(得分:0)

我刚刚做了你在Magento 1.7.0.2中所说的那些事情,但是我没有做扩展,看起来像是肮脏的方式。

我只是为AU做这件事,这就是我的所作所为:
1.在\ app \ design \ frontend \ base \ default \ template \ checkout \ onepage \ billing.phtml中找到你的billing.phtml
或者在\ app \ design \ frontend \ base \ default \ template \ persistent \ checkout \ onepage \ billing.phtml中 在底部的这些代码中:

    <script type="text/javascript">
jQuery(document).ready(function(){
CountryListener();
jQuery('#billing\\:country_id').change(function() {
CountryListener();
});     
});

var OriginalBillingCity = '<?php echo $this->escapeHtml($this->getAddress()->getCity()); ?>';
var OriginalBillingPostcode = '<?php echo $this->escapeHtml($this->getAddress()->getPostcode()); ?>';
function CountryListener()
{
var selectVal = jQuery('#billing\\:country_id option:selected').val();
if(selectVal == "AU"){
jQuery('#billing\\:region_id').change(function() {      ////add select change listener          
StateToCityList();
});
jQuery("#billing\\:city")
.replaceWith('<select id="billing:city" name="billing[city]" class="required-entry"><option value="">Select the State first, then you have options</option></select>');
jQuery("#billing\\:postcode")
.replaceWith('<select id="billing:postcode" name="billing[postcode]"><option value="">Please select the City first</option></select>');
}else{
jQuery("#billing\\:city")
.replaceWith('<input type="text" class="input-text required-entry absolute-advice" title="City" value="' + OriginalBillingCity + '" id="billing:city" name="billing[city]" autocomplete="off">');
jQuery("#billing\\:postcode")
.replaceWith('<input type="text" class="input-text required-entry absolute-advice" title="postcode" value="' + OriginalBillingPostcode + '" id="billing:postcode" name="billing[postcode]" autocomplete="off">');
} 
}

var state_city = [];
<?php echo $this->getCityList(); ?>
var city_postcode = [];
<?php echo $this->getPostCodeList(); ?>
//state_city.push({state:'New South Wales',city:'CHATSWORTH'});
//state_city.push({state:'New South Wales',city:'NAUGHTONS GAP',postcode:2470});
//state_city.push({state:'Queensland',city:'TERRICA',postcode:4387});

function StateToCityList(){
var StateText = jQuery('#billing\\:region_id option:selected').text();
if(StateText == "Please select region, state or province")
{   jQuery("#billing\\:city")
.replaceWith('<select id="billing:city" name="billing[city]" class="required-entry"><option value="">Select the State first, then you have options</option></select>');
} else{                             
/////////cookie////////         
/*var cookie_name = "billingstate";         
Mage.Cookies.clear(cookie_name);
Mage.Cookies.set(cookie_name, StateText);           
alert(Mage.Cookies.get(cookie_name));*/
//////////////////////////          
var CityList =  '<select id="billing:city" name="billing[city]" class="required-entry">'+
'<option>Select the City You live</option>';
for(i=0;i<state_city.length;i++)
{
if(state_city[i].state == StateText)
CityList += '<option value="'+state_city[i].city+'">'+state_city[i].city+'</option>';
}
CityList += '</select>';

jQuery("#billing\\:city")
.replaceWith(CityList);     
jQuery('#billing\\:city').change(function() {       ////add select change listener      
CityToPostcode();
});         
}
}   

function CityToPostcode(){      
var CityVal = jQuery('#billing\\:city option:selected').val();
var StateText = jQuery('#billing\\:region_id option:selected').text();
if(StateText == "Please select region, state or province" && CityVal == "Select the City You live")
{   jQuery("#billing\\:postcode")
.replaceWith('<select id="billing\\:postcode" name="billing[postcode]"><option value="">Please select the City first</option></select>');
} else{         
var PostcodeList =  '<select id="billing:postcode" name="billing[postcode]" >';
for(i=0;i<city_postcode.length;i++)
{
if(city_postcode[i].state == StateText && city_postcode[i].city == CityVal)
PostcodeList += '<option value="'+city_postcode[i].postcode+'">'+city_postcode[i].postcode+'</option>';
}
PostcodeList += '</select>';

jQuery("#billing\\:postcode")
.replaceWith(PostcodeList);     
}
}

</script>

然后在\ app \ code \ core \ Mage \ Checkout \ Block \ Onepage \ Billing.php中编辑Billing.php 创建两个函数如下:

    public function getCityList(){
require_once '/your server path/example.com/html/app/Mage.php';
Mage::app();    
$data = "";
/////////////// call SQL read////////////////
$connection_read = Mage::getSingleton('core/resource')->getConnection('core_read'); 
$sql = "SELECT * FROM state_to_city_AU";
$count = 1;
foreach ($connection_read->fetchAll($sql) as $State_City) {
$data .= 'state_city.push({state:"'.$State_City['state'].'", city:"'.$State_City['city'].'"});';    
}       
return $data;       
}

public function getPostCodeList(){
require_once '/your server path/example.com/html/app/Mage.php';
Mage::app();        
$data = "";
/////////////// call SQL read////////////////
$connection_read = Mage::getSingleton('core/resource')->getConnection('core_read');         
$sql = "SELECT * FROM city_to_postcode_AU";
$count = 1;
foreach ($connection_read->fetchAll($sql) as $city_postcode) {
$data .= 'city_postcode.push({state:"'.$city_postcode['state'].'", city:"'.$city_postcode['city'].'", postcode:"'.$city_postcode['postcode'].'"});';            
}       
return $data;       
}

最后,您需要准备添加两个数据库表state_to_city_AU(两列,州和城市)和city_to_postcode_AU(三列,州 - 城市 - 邮政编码)。

您需要以相同的方式发送地址代码。 它对我有用,你可以试试。