Skip to content

Instantly share code, notes, and snippets.

@putzflorian
Last active December 19, 2015 12:29
Show Gist options
  • Select an option

  • Save putzflorian/5955606 to your computer and use it in GitHub Desktop.

Select an option

Save putzflorian/5955606 to your computer and use it in GitHub Desktop.
Countrydropdown preselected list
<?php if($this->editmode){ ?>
<?= $this->translate('Auswahl') ?>:
<?php echo $this->select("mymode",array(
"store" => array(
array("myselect", $this->translate('Länder vorselektierung')),
array("myauswahl", $this->translate('Länder auswählen'))
),"reload" => true
)); ?>
<?php
$countries = \Zend_Locale::getTranslationList('Territory', $this->language, 2);
asort($countries);
$newcountries = array();
foreach($countries as $key => $value){
$newcountries[] = array($value, $value);
}
?>
<?php if($this->select("mymode")->text == 'myselect'){ ?>
<h2><?= $this->translate('Länder vorselektierung') ?></h2>
<?php while($this->block("contentblock")->loop()) { ?>
<?php echo $this->select("mySelect",array(
"store" => $newcountries,
"width" => 500
)); ?>
<?php } ?>
<?php } else { ?>
<h2><?= $this->translate('Länder auswählen') ?></h2>
<?php while($this->block("contentblock")->loop()) { ?>
<?php echo $this->select("mySelect",array(
"store" => $newcountries,
"width" => 500
)); ?>
<?php } ?>
<?php } ?>
<?php } else { ?>
<option value="">-- <?= $this->translate('bitte wählen') ?> --</option>
<?php if($this->select("mymode")->text == 'myselect'){ ?>
<?php
$bottomcountries = \Zend_Locale::getTranslationList('Territory', $this->language, 2);
asort($bottomcountries);
$top = array();
while($this->block("contentblock")->loop()) {
$top[] = $this->select("mySelect")->text;
}
$result = array_diff($bottomcountries, $top);
$all = array_merge($top, $result);
?>
<?php } else { ?>
<?php
$all = array();
while($this->block("contentblock")->loop()) {
$all[] = $this->select("mySelect")->text;
}
?>
<?php } ?>
<?php foreach ($all as $value){ ?>
<option value="<?= $value ?>"><?= $value ?></option>
<?php } ?>
<?php } ?>
@putzflorian
Copy link
Author

add namespaces & translations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment