Ejemplo n.º 1
0
 public function getHtmlElement()
 {
     $el = new Element('select', ['name' => $this->getName()]);
     foreach ($this->getConfig() as $value => $label) {
         $option = new Element('option', ['value' => $value]);
         $option->setText($label);
         if (strval($value) === strval($this->getValue())) {
             $option->setAttribute('selected', true);
         }
         $el->appendChild($option);
     }
     return $el;
 }
Ejemplo n.º 2
0
 public function getHtmlElement(array $attributes = null, $fieldCallback = null)
 {
     if ($fieldCallback !== null && !is_callable($fieldCallback)) {
         throw new \InvalidArgumentException("Argument 1 passed to buildHtml needs to be valid callback" . " or null");
     }
     $attributes = array_replace(['action' => '#', 'method' => Method::GET, 'enctype' => Type::X_WWW_FORM_URLENCODED], $attributes ? $attributes : []);
     $form = new Element('form', $attributes);
     foreach ($this->_fields as $field) {
         $el = $field->getHtmlElement();
         if ($fieldCallback) {
             $el = call_user_func($fieldCallback, $el);
         }
         $form->appendChild($el);
     }
     return $form;
 }