我哭鼻子能够创建此适当的方式,像 magento 不会,但如果你将拥有的所有国家的所有状态然后我觉得这是最完美的解决方案。如果您没有为所有国家的所有状态然后此模块不被,解决你的问题。如果任何人知道的正确方式然后请添加该解决方案通过注释。我在这里描述我到底怎么。
打开您的窗体,则在 Yournamespace/Modulename/Block/Adminhtml/Modulename/Edit/Tab/Form.php 中添加字段的下方
-
$country = $fieldset->addField(‘country’, ‘select’, array(
-
‘name’ => ‘country’,
-
‘label’ => ‘Country’,
-
‘values’ => Mage::getModel(‘adminhtml/system_config_source_country’) ->toOptionArray(),
-
‘onchange’ => ‘getstate(this)’,
-
));
-
-
$fieldset->addField(‘state’, ‘select’, array(
-
‘name’ => ‘state’,
-
‘label’ => ‘State’,
-
‘values’ => Mage::getModel(‘modulename/modulename’)
-
->getstate(‘AU’),
-
));
-
-
/*
-
* Add Ajax to the Country select box html output
-
*/
-
$country->setAfterElementHtml(“<script type=“text/javascript”>
-
function getstate(selectElement){
-
var reloadurl = ‘”. $this
-
->getUrl(‘modulename/adminhtml_modulename/state’) . “country/‘ + selectElement.value;
-
new Ajax.Request(reloadurl, {
-
method: ‘get’,
-
onLoading: function (stateform) {
-
$(‘state’).update(‘Searching…’);
-
},
-
onComplete: function(stateform) {
-
$(‘state’).update(stateform.responseText);
-
}
-
});
-
}
-
</script>“);
现在创建的 modulenamecontroller.php 文件,将会像这样的国家行动
-
public function stateAction() {
-
$countrycode = $this->getRequest()->getParam(‘country’);
-
$state = “<option value=”>Please Select</option>”;
-
if ($countrycode != ”) {
-
$statearray = Mage::getModel(‘directory/region’)->getResourceCollection() ->addCountryFilter($countrycode)->load();
-
foreach ($statearray as $_state) {
-
$state .= “<option value=’” . $_state->getCode() . “‘>” . $_state->getDefaultName() . “</option>”;
-
}
-
}
-
echo $state;
-
}
(责任编辑:最模板) |