If your Multiselect element contains a list of countries, I would just populate the default value in your element value according to the address in the URL.
To do this, you can create your own Zend_Form_Element as follows:
class My_Form_Element_SelectCountry extends Zend_Form_Element_Select { protected $_translatorDisabled = true; public function init() { $locale = Zend_Registry::get('Zend_Locale'); if (!$locale) { throw new Exception('No locale set in registry'); } $countries = Zend_Locale::getTranslationList('territory', $locale, 2); unset($countries['ZZ']); // fetch lang parameter and set US if there is no param $request = Zend_Controller_Front::getInstance()->getRequest(); $lang = $request->getParam('lang', 'US'); // sort your country list $oldLocale = setlocale(LC_COLLATE, '0'); setlocale(LC_COLLATE, 'en_US'); asort($countries, SORT_LOCALE_STRING); setlocale(LC_COLLATE, $oldLocale); // check weither the lang parameter is valid or not and add it to the list if (isset($countries[$lang])) { $paramLang = array($lang => $countries[$lang]); $countries = array_merge($paramLang, $countries); } $this->setMultiOptions($countries); }
}
You get the idea from this user form. If what you are trying to do is not a Multiselect field filled with a list of countries, but a list of languages instead, then the logic will be the same, you just need to change the call to the static method Zend_Locale::getTranslationList() and capture all the information you need.
One more thing, if you only need one element in your Multiselect element, go to Zend_Form_Element_Hidden .
This is a lot of ifs, but I can’t understand how your Multiselect element looks exactly from your question.
Now let's take a look at the validation side, when you use the Multiselect element, Zend_Framework automatically adds an InArray validator, which means you have nothing to do to check whether the data is sent correctly or not. isValid is going to do it for you.
The user can specify the default parameter, and everything will be fine, or he will change / delete this parameter, and the default parameter (en_US in this case, see the code above) will be set as the default value for the Multiselect field.
To answer your last question, no, not against the framework, to check the variable set by the user and compare it with an array (for example, from getTranslationList() ). I would say that this is even the recommended way to do something.