private function _addElementState() { $this->addElement('select', 'state_id', array('required' => true, 'label' => 'State', 'dimension' => 4)); $el = $this->getElement('state_id'); $cd = new Location_Domain_State(); $c = $cd->getAll('name'); $el->addMultiOption(null, null); foreach ($c as $state) { $el->addMultiOption($state->getId(), $state->getName()); } if ($this->_model && $this->_model->state_id) { $el->setValue($this->_model->state_id); } }
/** * Adds an element StateId.<br/> * Defaults:<br/> * name = state_id<br/> * requires = false<br/> * label = State<br/> * placeholder = 'Choose a state'<br/> * dimension = 4<br/> * modelfield = state_id<br/> * * @param Zend_Form $form The Zend_Form object where the element will be added * @param array $options The options to pass in the element */ public function addElementStateId($form, $options = array()) { $elementName = isset($options['name']) ? $options['name'] : 'state_id'; $modelField = isset($options['modelfield']) ? $options['modelfield'] : 'state_id'; $form->addElement('select', $elementName, array('filters' => array('StringTrim'), 'label' => isset($options['label']) ? $options['label'] : 'State', 'dimension' => isset($options['dimension']) ? $options['dimension'] : 4, 'placeholder' => 'Choose a state', 'required' => isset($options['required']) ? $options['required'] : false, 'value' => $this->_model ? $this->_model->{$modelField} : '')); $el = $form->getElement($elementName); $cd = new Location_Domain_State(); $c = $cd->getAll(array('orderby' => 'name')); $el->addMultiOption(null, null); foreach ($c as $city) { $el->addMultiOption($city->getId(), $city->getName()); } if ($this->_model && $this->_model->{$modelField}) { $el->setValue($this->_model->{$modelField}); } else { $el->setValue(null); } }