/** * Set the countries available. * * @param T_Geo_CountryGateway $countries * @param string $default default country code (e.g. GB) * @return T_Form_Address fluent interface */ function setCountries(T_Geo_CountryGateway $countries, $default = 'GB') { $this->countries = $countries; // add (or overwrite) form element $world = $countries->getAll(); $options = array(); foreach ($world as $c) { $options[$c->getCode()] = $c->getName(); } $country = new T_Form_Select($this->getAlias() . '_country', 'Country'); $country->setOptions($options)->setDefault($default); $this->addChild($country, $this->getAlias() . '_country'); return $this; }
/** * Visit select element. * * @param T_Form_Select $node select node. */ function visitFormSelect(T_Form_Select $node) { $attributes = $node->getAllAttributes(); $attributes += array('name' => $node->getFieldname(), 'id' => $this->getNodeId($node)); $xhtml = $this->createLabel($node); // create <select> $xhtml .= $this->preElement($node); $xhtml .= $this->indent . '<select '; foreach ($attributes as $key => $value) { $xhtml .= $key . '="' . $this->escape($value) . '"' . EOL . $this->indent . ' '; } $xhtml = rtrim($xhtml) . ' >' . EOL; $this->changeIndent(1); // render the option list $options = $node->getOptions(); $default = $node->getDefault(); foreach ($options as $value => $label) { $xhtml .= $this->indent . '<option value="' . $this->escape($value) . '"'; if (strcmp($value, $default) === 0) { $xhtml .= ' selected="selected"'; } $xhtml .= '>' . $this->escape($label) . '</option>' . EOL; } // close <select> $this->changeIndent(-1); $xhtml .= $this->indent . '</select>' . EOL; $xhtml .= $this->postElement($node); $this->addXhtml($xhtml); }
/** * Gets a new instance of the select element. * * @param string $alias element alias * @param string $label element label * @return T_Form_Select text input to test. */ function getInputElement($alias, $label) { $input = new T_Form_Select($alias, $label); $input->setOptions(array('value1' => 'Label 1', 'value2' => 'Label 2', 'value3' => 'Label 3')); return $input; }
/** * Get the test element. * * @return T_Form_Upload */ function getElement($name, $label) { $element = new T_Form_Select($name, $label); $element->setOptions(array('test' => '1', 'dave' => 'fred', 'swadg' => 'asdgf')); return $element; }